<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Java 入门基础（一） | 铃仙小屋</title><meta name="author" content="Reisen"><meta name="copyright" content="Reisen"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="description" content="javaSE基础javaSe 整体大纲 java基础 （循环，数组） OOP API  基础 编程的本质&#x3D;数据结构+算法 什么是编程：就是让计算机按自己的意图去工作  编程语言的发展史（了解） 机器语言：0101 汇编语言:   助记符 高级语言：java,c,c++,python,basic  为什么是java流行的语言：  java,python,c,C++,javascript,g">
<meta property="og:type" content="article">
<meta property="og:title" content="Java 入门基础（一）">
<meta property="og:url" content="https://www.reisen7.cc/2023/02/24/Java_%E5%85%A5%E9%97%A8/index.html">
<meta property="og:site_name" content="铃仙小屋">
<meta property="og:description" content="javaSE基础javaSe 整体大纲 java基础 （循环，数组） OOP API  基础 编程的本质&#x3D;数据结构+算法 什么是编程：就是让计算机按自己的意图去工作  编程语言的发展史（了解） 机器语言：0101 汇编语言:   助记符 高级语言：java,c,c++,python,basic  为什么是java流行的语言：  java,python,c,C++,javascript,g">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s3.bmp.ovh/imgs/2023/02/25/1a3e9c86350e5726.jpg">
<meta property="article:published_time" content="2023-02-24T14:16:01.000Z">
<meta property="article:modified_time" content="2024-04-15T03:18:16.191Z">
<meta property="article:author" content="Reisen">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s3.bmp.ovh/imgs/2023/02/25/1a3e9c86350e5726.jpg"><link rel="shortcut icon" href="/img/amber.png"><link rel="canonical" href="https://www.reisen7.cc/2023/02/24/Java_%E5%85%A5%E9%97%A8/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: {"limitDay":500,"position":"top","messagePrev":"It has been","messageNext":"days since the last update, the content of the article may be outdated."},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":300},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: Reisen","link":"链接: ","source":"来源: 铃仙小屋","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Java 入门基础（一）',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-04-15 11:18:16'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/universe.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css" /><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (true) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="http://q1.qlogo.cn/g?b=qq&amp;nk=328170849&amp;s=640" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">6</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">5</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">1</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 休闲</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 图片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comments/index.html"><i class="fa-fw fas fa-heartbeat"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s3.bmp.ovh/imgs/2023/02/25/1a3e9c86350e5726.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="铃仙小屋"><img class="site-icon" src="/img/amber.png"/><span class="site-name">铃仙小屋</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 休闲</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 图片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comments/index.html"><i class="fa-fw fas fa-heartbeat"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Java 入门基础（一）</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-02-24T14:16:01.000Z" title="发表于 2023-02-24 22:16:01">2023-02-24</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-04-15T03:18:16.191Z" title="更新于 2024-04-15 11:18:16">2024-04-15</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%9F%BA%E7%A1%80/">基础</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">13k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>48分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Java 入门基础（一）"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="javaSE基础"><a href="#javaSE基础" class="headerlink" title="javaSE基础"></a>javaSE基础</h1><h2 id="javaSe-整体大纲"><a href="#javaSe-整体大纲" class="headerlink" title="javaSe 整体大纲"></a>javaSe 整体大纲</h2><ol>
<li>java基础 （循环，数组）</li>
<li>OOP</li>
<li>API</li>
</ol>
<h2 id="基础"><a href="#基础" class="headerlink" title="基础"></a>基础</h2><ul>
<li>编程的本质&#x3D;数据结构+算法</li>
<li>什么是编程：就是让计算机按自己的意图去工作</li>
</ul>
<h2 id="编程语言的发展史（了解）"><a href="#编程语言的发展史（了解）" class="headerlink" title="编程语言的发展史（了解）"></a>编程语言的发展史（了解）</h2><ol>
<li>机器语言：0101</li>
<li>汇编语言:   助记符</li>
<li>高级语言：java,c,c++,python,basic</li>
</ol>
<h2 id="为什么是java"><a href="#为什么是java" class="headerlink" title="为什么是java"></a>为什么是java</h2><p>流行的语言：</p>
<ul>
<li>java,python,c,C++,javascript,go…..</li>
<li>语言没有好坏之分，只有适不适用？</li>
</ul>
<p>厨房中的刀，哪把刀更好：砍刀，切菜刀，西瓜刀，水果刀？</p>
<ul>
<li>每个语言都有适用的场景</li>
<li>数据分析：python,</li>
<li>3D游戏：C++   </li>
<li>前端页面：javascript</li>
<li>应用程序的后台：java</li>
</ul>
<h2 id="回顾"><a href="#回顾" class="headerlink" title="回顾"></a>回顾</h2><p>1.学习方法：编码-》巩固-》检索    3F：focus-&gt;feedback-&gt;fix<br>2.课程   se:1.基础 2.oop,3API<br>3.编程的基础： 数据结构+算法&#x3D;程序<br>4.编程语言的发展史</p>
<ol>
<li>机器语言</li>
<li>汇编语言</li>
<li>高级语言</li>
</ol>
<p>5.java</p>
<ul>
<li>企业后台</li>
<li>安卓</li>
<li>大数据</li>
<li>桌面</li>
</ul>
<p>6.java语言的发展史</p>
<h2 id="java语言的发展"><a href="#java语言的发展" class="headerlink" title="java语言的发展"></a>java语言的发展</h2><p>高斯林（高司令）：嵌入式程序</p>
<p>99年，三个版本：javase,javame,javaee</p>
<ul>
<li>LTS</li>
<li>JDK8</li>
<li>JDK11</li>
<li>JDK17</li>
</ul>
<h2 id="java-语言的特点"><a href="#java-语言的特点" class="headerlink" title="java 语言的特点"></a>java 语言的特点</h2><ul>
<li>面向对象</li>
<li>简单</li>
<li>跨平台</li>
</ul>
<h2 id="java语言的三个版本"><a href="#java语言的三个版本" class="headerlink" title="java语言的三个版本"></a>java语言的三个版本</h2><ul>
<li>A：javaSE：标准版本：基础，桌面级应用</li>
<li>B：javaEE：企业版：服务器端的大网络，分布式</li>
<li>C：javaME：微型版本：嵌入式设备，小设备</li>
</ul>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/24/1a4a6b994af3b594.png"></p>
<h2 id="环境安装"><a href="#环境安装" class="headerlink" title="环境安装"></a>环境安装</h2><h3 id="JDK"><a href="#JDK" class="headerlink" title="JDK"></a>JDK</h3><blockquote>
<p>java development kid:java开发包</p>
<p>作用：开发，运行java程序</p>
<p><strong>JRE</strong>:java runtime environmentjava 运行环境</p>
<p>作用：运行java程序</p>
<p>JDK包含了JRE</p>
<p><strong>JVM</strong>：java virtual machine:java虚拟机</p>
<p>作用：用来运行java程序  不包含类库和命令</p>
<p>JDK中包含了JRE，JRE中包含了JVM</p>
</blockquote>
<h2 id="安装JDK"><a href="#安装JDK" class="headerlink" title="安装JDK"></a>安装JDK</h2><p>建议：安装 11，8，</p>
<p>安装注意事项</p>
<ol>
<li>傻瓜式安装，按步骤来就行</li>
<li>安装路径不要有空格，不要使用中文路径   </li>
<li>安装后会有两个目录<ul>
<li>bin:包含了java命令：javac(编译)，java(运行)，javadoc(生成文档)</li>
<li>lib:包含了java类库</li>
</ul>
</li>
</ol>
<p>配置：</p>
<blockquote>
<p>配置环境变量？</p>
</blockquote>
<h2 id="DOS命令"><a href="#DOS命令" class="headerlink" title="DOS命令"></a>DOS命令</h2><p>DOS：disk operation system：命令行   </p>
<blockquote>
<p>命令：</p>
</blockquote>
<ul>
<li><p>cd:改变目录</p>
</li>
<li><p>dir:查看当前目录下的内容</p>
</li>
<li><p>盘符：切换到其它盘，例如 D:</p>
</li>
<li><p>d:切换到D盘</p>
</li>
<li><p>cd ..:切换到上层目录</p>
</li>
<li><p>cd bin:进入取bin子目录</p>
</li>
<li><p>dir:显示当前目录中的内容   </p>
<blockquote>
<p>问题？<br>java.exe,javac.exe在  d:&#x2F;java&#x2F;jdk-11.0.8&#x2F;bin下，如果想使用java,javac命令，必须先进入到d:&#x2F;java&#x2F;jdk-11.0.8&#x2F;bin下才可以使用，如果希望在任何一个目录下都使用此命令，则需要配置环境变量才可以   </p>
<p>环境变量中有一个叫path的<br>path的作用是，当运行一个命令时，先从当前路径找，如找不到，再去path中找   </p>
<p>如果在path中设置一个值  d:&#x2F;java&#x2F;jdk-11.0.8&#x2F;bin<br>当我们在 e:盘下，运行  java</p>
</blockquote>
</li>
<li><p>1.先在 e:&#x2F;下找java</p>
</li>
<li><p>2.如找不到，再到path下找</p>
</li>
</ul>
<blockquote>
<p>环境变量<br>path:路径<br>classpath:类路径   .d:&#x2F;java&#x2F;jdk-11.0.8&#x2F;lib</p>
</blockquote>
<p>window: 图形界面</p>
<p>android:图形</p>
<p>linux:有图形 </p>
<h2 id="第一个java程序"><a href="#第一个java程序" class="headerlink" title="第一个java程序"></a>第一个java程序</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HelloWorld</span>&#123;	</span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span>&#123;</span><br><span class="line">		System.out.println(<span class="string">&quot;这是我的第一个java程序，我好高兴呀，今天晚上给自己加一个鸡腿吧&quot;</span>);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>HelloWorld:是类名，类名必须要与文件名相同   （HelloWorld.java</li>
<li>System.out.println(“”)：代表输出   “”中可以写任何字符串 </li>
<li>所有的标点符号都是英文半角   </li>
<li>java是区分大小写的</li>
</ol>
<p>​	</p>
<h2 id="HelloWorld详解"><a href="#HelloWorld详解" class="headerlink" title="HelloWorld详解"></a>HelloWorld详解</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Hello</span>&#123;</span><br><span class="line">   <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span>&#123;</span><br><span class="line">       </span><br><span class="line">       System.out.println();</span><br><span class="line">   &#125; </span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//Hello是类名</span></span><br><span class="line"><span class="comment">//public static void main(String[] args):是主函数，程序的入口，如果想直接运行此类，必须有此方法  </span></span><br><span class="line"><span class="comment">//System.out.println();输出内容后换行</span></span><br><span class="line"><span class="comment">//System.out.print();输出内容后不换行</span></span><br><span class="line"><span class="comment">//无论是print还是println都只能输出一个内容，内容可以是字符串，数字，布尔等等  </span></span><br><span class="line"></span><br><span class="line"><span class="comment">//9+9  </span></span><br><span class="line"><span class="comment">//&quot;hello&quot;+&quot;hello&quot;+9</span></span><br></pre></td></tr></table></figure>

<h2 id="java命令"><a href="#java命令" class="headerlink" title="java命令"></a>java命令</h2><blockquote>
<p>javac:编译<br>java:运行<br>javadoc:生成文档</p>
</blockquote>
<blockquote>
<p>javac语法</p>
<p>javac 文件名.java<br>javac HelloWorld.java<br>作用：将.java的源代码编译成.class文件，如果代码有错误，将无法完成编译   </p>
</blockquote>
<blockquote>
<p>java 语法</p>
<p>java 类名<br>java HelloWorld<br>注意：千万不要写.class<br>作用：运行java类，要求此类必须有主函数   </p>
</blockquote>
<blockquote>
<p>javadoc:生成文档<br>javadoc 类名.java</p>
</blockquote>
<h2 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h2><blockquote>
<p>作用：为了让程序员更容易理解代码的含义，可以使用注释加以说明   注释不会影响代码的运行</p>
<p>注释有三种   </p>
<p>&#x2F;&#x2F;:单行<br>&#x2F;*  <em>&#x2F;：块注释<br>&#x2F;</em>* *&#x2F;：文档注释</p>
</blockquote>
<h1 id="java编程基础"><a href="#java编程基础" class="headerlink" title="java编程基础"></a>java编程基础</h1><h2 id="关键字"><a href="#关键字" class="headerlink" title="关键字"></a>关键字</h2><ul>
<li><p>什么是关键字：在java语言有，有特殊含义的一些单词就是关键字   </p>
</li>
<li><p>关键字的特点：全部都有小写</p>
</li>
</ul>
<h2 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h2><ul>
<li>什么标识符：用来标识某种东西的符号就是标识符</li>
</ul>
<blockquote>
<p>比如：类，方法名，变量名，参数名，</p>
</blockquote>
<p>定义标识符的规则</p>
<ul>
<li><p>标识符中可包含字母，数字，_,$,中文也可以（不建议）</p>
</li>
<li><p>不能以数字开头</p>
</li>
<li><p>不能是关键字</p>
</li>
<li><p>长度无限制，最好做到“见名知义”</p>
<p>  ​</p>
</li>
</ul>
<p>	</p>
<h2 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h2><p>变量：就是内存中的一个区域，为了便于使用，需要给变量起个名字</p>
<p>变量用法：</p>
<ol>
<li><p>变量一定要先定义，再使用</p>
</li>
<li><p>定义变量的格式是 </p>
<blockquote>
<p>数据类型 变量名&#x3D;初始值</p>
</blockquote>
</li>
<li><p>变量的值是可以改变的</p>
</li>
<li><p>在一个作用域中，变量名是不能重复的</p>
</li>
</ol>
<h2 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h2><p>java的数据类型分为两大类，分别是</p>
<ul>
<li>基本数据类型</li>
<li>引用数据类型<ul>
<li>类，接口，数组</li>
</ul>
</li>
</ul>
<h3 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h3><ul>
<li><p>整数</p>
<ul>
<li>byte  :1</li>
<li>short:1</li>
<li>int :2</li>
<li>long:2</li>
</ul>
</li>
<li><p>浮点数</p>
<ul>
<li>float:45.6f</li>
<li>double:444.4</li>
</ul>
</li>
<li><p>字符</p>
<ul>
<li>char     ‘a’</li>
</ul>
</li>
<li><p>布尔</p>
<ul>
<li>boolean  :true,false</li>
</ul>
</li>
</ul>
<h4 id="整数："><a href="#整数：" class="headerlink" title="整数："></a>整数：</h4><ul>
<li><p>byte:1个字节</p>
<ul>
<li><p>位（bit）</p>
<p>01：bit，每个一个bit只能存储两个值   </p>
<p>一个字节等于8位二进制</p>
<blockquote>
<p>10101011</p>
</blockquote>
<p>byte &#x3D; -128~127;</p>
</li>
</ul>
<p>		</p>
</li>
<li><p>short:2个字节</p>
</li>
<li><p>int:4个字节</p>
</li>
<li><p>long:8个字节</p>
</li>
</ul>
<h4 id="关于容量的换算关系"><a href="#关于容量的换算关系" class="headerlink" title="关于容量的换算关系"></a>关于容量的换算关系</h4><p>字节 B   byte</p>
<p>1KB-&gt;1024B</p>
<p>1MB-&gt;1024KB</p>
<p>1GB-&gt;1024MB</p>
<p>1TB-&gt;1024GB</p>
<p>1PB-&gt;1024TB</p>
<h4 id="进制的转换"><a href="#进制的转换" class="headerlink" title="进制的转换"></a>进制的转换</h4><blockquote>
<p>1.10进制-》二进制<br>        除2取余法   </p>
<p>2.二进制-》十进制<br>        乘权相加法<br>    110101<br>    1+4+16+32&#x3D;53<br>3.二进制-》十六进制<br>    1011 1010<br>      B	   A<br>     100011111<br>4.十六进制-》二进制<br>     6E-》</p>
</blockquote>
<h3 id="字面值（literal）"><a href="#字面值（literal）" class="headerlink" title="字面值（literal）"></a>字面值（literal）</h3><p>字面值也叫直接量   </p>
<blockquote>
<p>1.整数的字面值的类型默认为是int<br>2.十六进制 0x开头<br>3.八进制以0开头，例如  int a&#x3D;011<br>4.如果想表示一个long值，可以使用 L结尾，例如 long a&#x3D;12312312399L</p>
</blockquote>
<h3 id="浮点型"><a href="#浮点型" class="headerlink" title="浮点型"></a>浮点型</h3><table>
<thead>
<tr>
<th></th>
<th>字节</th>
<th>范围</th>
</tr>
</thead>
<tbody><tr>
<td>float</td>
<td>4</td>
<td>-3.403E38 ~ 3.403E38</td>
</tr>
<tr>
<td>double</td>
<td>8</td>
<td>-1.798E308 ~ 1.798E308</td>
</tr>
</tbody></table>
<blockquote>
<p>总结<br>1.浮点数只能表示出一个近似数，而不能表示出一个准确的数<br>2.浮点数的字值的类型是double,如果想表示一个float，应该使用 F结尾   </p>
</blockquote>
<h3 id="字符型"><a href="#字符型" class="headerlink" title="字符型"></a>字符型</h3><p>用 一对‘’引起的单个字符就是字符，字符可以以数字，英文字母，标点符号，还可以表示任何语言的单字符   例如，中文，法文，俄文，日文   </p>
<blockquote>
<p>每个字符存储时，都会转换成与之对应的数字<br>字符与数字之间的对应关系就是一种字符集   UTF-8   GBK,GB2312<br>char有三种表示方式<br>1.‘’<br>2.‘\转义字符’ ，例如 ‘\n’:换行<br>3.unicode码    ‘\uXXXX’</p>
</blockquote>
<h3 id="boolean"><a href="#boolean" class="headerlink" title="boolean"></a>boolean</h3><blockquote>
<p>boolean叫布尔<br>只有两个值，分别是true,false<br>通常来说，可以使用boolean来存储一个状态   </p>
<p>是否打开音乐<br>boolean isMusic&#x3D;false</p>
</blockquote>
<h3 id="String类型"><a href="#String类型" class="headerlink" title="String类型"></a>String类型</h3><blockquote>
<p>String代表字符串，即用双引号引起的多个字符序列<br>String不是基本数据类型，而是一种引用类型   </p>
<p>String name&#x3D;”刘备”</p>
</blockquote>
<h2 id="java代码三级跳"><a href="#java代码三级跳" class="headerlink" title="java代码三级跳"></a>java代码三级跳</h2><blockquote>
<p>1.表达式<br>    类似于语文中的汉字，词组，例如 a+b,c*d<br>2.语句<br>    类似于语文中的句子。以   号结束   一个语句中会包含多个表达式，</p>
<p>​    int a&#x3D;5;<br>​	int b&#x3D;a+b;<br>​	c&#x3D;sum+a;<br>3.代码段<br>​	相当于语文的作文，一个代码段中包含多个语句   </p>
</blockquote>
<h2 id="数据类型的转换"><a href="#数据类型的转换" class="headerlink" title="数据类型的转换"></a>数据类型的转换</h2><blockquote>
<p>两种转换<br>1.自动转换：低精度向高精度可以自动转换，安全<br>2.强制转换：高精度向低精度转换时可以采用强制转换，强转可能会造成精度丢失   </p>
</blockquote>
<blockquote>
<p>数值类的的精度<br>byte-&gt;short-&gt;int-&gt;long-&gt;float-&gt;double<br>         char</p>
</blockquote>
<h4 id="自动类型转换发生在两种情况"><a href="#自动类型转换发生在两种情况" class="headerlink" title="自动类型转换发生在两种情况"></a>自动类型转换发生在两种情况</h4><ul>
<li>赋值</li>
<li>运算</li>
</ul>
<h4 id="强制类型转换"><a href="#强制类型转换" class="headerlink" title="强制类型转换"></a>强制类型转换</h4><ul>
<li>高精度向低精度转换时，可使用强转</li>
<li>强转的语法是  （数据类型）   例如  long b&#x3D;6677;  int a&#x3D;(int)b;</li>
</ul>
<h2 id="Scanner"><a href="#Scanner" class="headerlink" title="Scanner"></a>Scanner</h2><blockquote>
<p>&#x2F;&#x2F;有交互的程序<br>交互的方式主要用两种<br>1.命令行<br>2.图形<br>Scanner叫扫描器，他可以接收用户输入的数据   例如数字，字符串，布尔值等   </p>
</blockquote>
<blockquote>
<p>使用Scanner的步骤<br>1.导包 import java.util.*<br>2.创建Scanner对象<br>    Scanner s&#x3D;new Scanner(System.in)<br>3.接收数据<br>    int a&#x3D;s.nextInt()</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;  <span class="comment">//1.导包</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Circle</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> </span><br><span class="line">	&#123;</span><br><span class="line">		<span class="comment">//2.创建一个扫描器  </span></span><br><span class="line">		Scanner scanner=<span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"></span><br><span class="line">		System.out.println(<span class="string">&quot;请输入半径&quot;</span>);</span><br><span class="line">		<span class="comment">//3.接收一个半径</span></span><br><span class="line">		<span class="type">double</span> r=scanner.nextDouble();</span><br><span class="line"></span><br><span class="line">		<span class="type">double</span> area=r*r*<span class="number">3.14</span>;</span><br><span class="line"></span><br><span class="line">		System.out.println(<span class="string">&quot;圆的面积是：&quot;</span>+area);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h2><p> 运算符可以有两种分在方式</p>
<ol>
<li>功能<ul>
<li>算术运算符</li>
<li>赋值运算符</li>
<li>比较运算符</li>
<li>位运算符</li>
<li>逻辑运算符</li>
<li>条件（三元）运算符</li>
</ul>
</li>
<li>操作数的个数<ul>
<li>一元操作符：    ++b, </li>
<li>二元操作符：    a+b</li>
<li>三元操作符      a&gt;b?a:b</li>
</ul>
</li>
</ol>
<h3 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符"></a>算术运算符</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">++,--</span><br><span class="line">可以放在操作数之前，也可以放在操作数之后  </span><br><span class="line"></span><br><span class="line">a++操作符有作用  </span><br><span class="line"><span class="number">1.</span>对a做一个加操作  </span><br><span class="line"><span class="number">2.</span>a++也是一个表达式，即将表达式的结果赋给一个变量  </span><br><span class="line">		b=a++;</span><br><span class="line">		b=++a;</span><br><span class="line">		</span><br><span class="line">a++;</span><br><span class="line">++a;	</span><br></pre></td></tr></table></figure>



<h3 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">=</span><br><span class="line">例如： a=<span class="number">9</span>+<span class="number">8</span>;</span><br><span class="line">特点：</span><br><span class="line"><span class="number">1.</span>操作符的结合性是从右到左  </span><br><span class="line"><span class="number">2.</span>操作符左侧一定是一个变量  </span><br></pre></td></tr></table></figure>



<h3 id="比较运算符"><a href="#比较运算符" class="headerlink" title="比较运算符"></a>比较运算符</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">==  </span><br><span class="line">!=</span><br><span class="line">&lt;</span><br><span class="line">=</span><br><span class="line">&lt;=</span><br><span class="line"><span class="keyword">instanceof</span></span><br><span class="line"></span><br><span class="line">所有比较运算符的计算结果的类型都是<span class="type">boolean</span>; <span class="literal">true</span>,<span class="literal">false</span>;</span><br><span class="line"></span><br><span class="line">注意，</span><br><span class="line">	=是赋值</span><br><span class="line">	==是比较  </span><br></pre></td></tr></table></figure>



<h3 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h3> <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">与： &amp; ,&amp;&amp;</span><br><span class="line">或:  |  ||</span><br><span class="line">非：  !</span><br><span class="line">异或： ^</span><br><span class="line"></span><br><span class="line">与的语法</span><br></pre></td></tr></table></figure>

 <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">表达式<span class="number">1</span>  &amp; 表达式<span class="number">2</span>  </span><br><span class="line">表达式<span class="number">1</span>  &amp;&amp; 表达式<span class="number">2</span>  </span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"> 要求，两个表达式都是布尔表达式  </span><br><span class="line"> 即，两个表达式的结果同时为<span class="literal">true</span>时，与后的结果才<span class="literal">true</span>;	</span><br><span class="line"></span><br><span class="line">或：  ｜  ｜｜</span><br><span class="line">作用：两个操作数的结果，只要有一个为<span class="literal">true</span>,那么或的结果就为<span class="literal">true</span>;</span><br><span class="line">非：</span><br><span class="line">取反  </span><br><span class="line">!<span class="literal">true</span>;=<span class="literal">false</span>;</span><br><span class="line">!<span class="literal">false</span>:=<span class="literal">true</span>;</span><br><span class="line"></span><br><span class="line">异或：</span><br><span class="line">作用：两个操作数不同时为<span class="literal">true</span>,否则为<span class="literal">false</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&amp;,&amp;&amp;的区别？</span><br><span class="line">&amp;，&amp;&amp;都是逻辑与，计算的结果是相同的  但运算的过程是有区别的？</span><br><span class="line">例如</span><br><span class="line">a&amp;&amp;b;</span><br><span class="line">假如，a的结果是<span class="literal">false</span>;那么是否需要计算b，才知道整个表达式的结果  </span><br><span class="line"></span><br><span class="line">区别：</span><br><span class="line">&amp;：无论第一个操作数结果是什么，都会计算所有表达式  </span><br><span class="line">&amp;&amp;：如果第一个操作数的结果是<span class="literal">false</span>,那么将不会计算第二个表达式  </span><br></pre></td></tr></table></figure>



<h3 id="位运算符"><a href="#位运算符" class="headerlink" title="位运算符"></a>位运算符</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">操作对象：整数（<span class="type">byte</span>,<span class="type">short</span>,<span class="type">int</span>,<span class="type">long</span>）  </span><br><span class="line">作用：将整数转换成二进制后，按位进行运算  常用的操作有，位移，按位与，或，异或  </span><br><span class="line">位运算的优点：效率高  </span><br><span class="line"></span><br><span class="line">:按位右移</span><br><span class="line">&lt;&lt;:按位左移</span><br><span class="line"></span><br><span class="line">:无符号右移</span><br><span class="line">&amp;:按位与</span><br><span class="line">|:按位或</span><br><span class="line">^:按位异或</span><br><span class="line"></span><br><span class="line"><span class="number">895</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="条件运算符"><a href="#条件运算符" class="headerlink" title="条件运算符"></a>条件运算符</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">语法</span><br><span class="line">布尔表达式？表达式<span class="number">1</span>：表达式<span class="number">2</span>  </span><br><span class="line"><span class="type">int</span> c=a&gt;b？a：b;</span><br></pre></td></tr></table></figure>



<h1 id="Java进阶"><a href="#Java进阶" class="headerlink" title="Java进阶"></a>Java进阶</h1><h2 id="流程控制"><a href="#流程控制" class="headerlink" title="流程控制"></a>流程控制</h2><blockquote>
<p>三种<br>顺序结构<br>分支（选择）结构：branch<br>循环结构：loop</p>
</blockquote>
<blockquote>
<p>顺序：<br>    程序从上到下，依次执行   </p>
</blockquote>
<h2 id="分支语句"><a href="#分支语句" class="headerlink" title="分支语句"></a>分支语句</h2><p>分支语句分为if,switch</p>
<h2 id="if语句"><a href="#if语句" class="headerlink" title="if语句"></a>if语句</h2><h3 id="单分支"><a href="#单分支" class="headerlink" title="单分支"></a>单分支</h3><p>语法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(布尔表达式)&#123;</span><br><span class="line">   语句块 </span><br><span class="line">&#125;</span><br><span class="line">。。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>适用场景：<br>    为程序增加一个可能执行的代码，此代码有可能执行，有可能不执行   </p>
</blockquote>
<h3 id="双分支"><a href="#双分支" class="headerlink" title="双分支"></a>双分支</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(布尔表达式)&#123;</span><br><span class="line">    语句块<span class="number">1</span>  </span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">    语句块<span class="number">2</span>  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="多分支"><a href="#多分支" class="headerlink" title="多分支"></a>多分支</h3><p>语法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(布尔表达式)&#123;</span><br><span class="line">    </span><br><span class="line">&#125;<span class="keyword">else</span> <span class="keyword">if</span>(布尔表达式<span class="number">2</span>)&#123;</span><br><span class="line">    </span><br><span class="line">&#125;<span class="keyword">else</span> <span class="keyword">if</span>(布尔表达式<span class="number">3.</span>。。。)&#123;</span><br><span class="line">    </span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>关于if的小结<br>1.完整的if语句中，包含 if-else if-else<br>2.if语法中，if是必须存在的， else if可有0到n个，可以有0到1个else<br>3.如果存在else,else一定放在最后<br>4.多分支语句中，最多只能执行一个分支，执行此分支后，分支语句结束   </p>
</blockquote>
<h3 id="if的嵌套"><a href="#if的嵌套" class="headerlink" title="if的嵌套"></a>if的嵌套</h3><blockquote>
<p>在一个分支语句块中包含另一个分支语句<br>适用场景：适合解决较为复杂的逻辑问题   </p>
</blockquote>
<blockquote>
<p>例如：<br>    登录<br>    1.成功 用户名，密码，验证码<br>    2.失败<br>        1.验证码？<br>        2.用户名，或密码错误，但少于3次<br>        3.用户名，或密码错误，但大于等于3次   锁定（1个小时）   </p>
</blockquote>
<p>语法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(条件)&#123;</span><br><span class="line">	System.out.println();</span><br><span class="line">	i++;</span><br><span class="line">	<span class="keyword">if</span>()&#123;</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line">&#125;<span class="keyword">else</span> <span class="keyword">if</span>(条件)&#123;</span><br><span class="line">		<span class="keyword">if</span>()&#123;</span><br><span class="line">		</span><br><span class="line">		&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">			</span><br><span class="line">		&#125;</span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="if语句的简化"><a href="#if语句的简化" class="headerlink" title="if语句的简化"></a>if语句的简化</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//如果if语句块中只包含一行代码，那么｛｝可以省略，（但不建议省略）</span></span><br><span class="line"><span class="keyword">if</span>(<span class="literal">true</span>)</span><br><span class="line">	System.out.println(<span class="string">&quot;ok&quot;</span>);</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">	System.out.println(<span class="string">&quot;else&quot;</span>);</span><br></pre></td></tr></table></figure>

<h3 id="switch-语句"><a href="#switch-语句" class="headerlink" title="switch 语句"></a>switch 语句</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法</span></span><br><span class="line"><span class="keyword">switch</span>(表达式)&#123;</span><br><span class="line">	<span class="keyword">case</span> 值<span class="number">1</span>：</span><br><span class="line">		语句;</span><br><span class="line">		<span class="keyword">break</span>;</span><br><span class="line">	<span class="keyword">case</span> 值<span class="number">2</span>：</span><br><span class="line">		语句;</span><br><span class="line">		<span class="keyword">break</span>;</span><br><span class="line">	<span class="keyword">default</span>:</span><br><span class="line">		语句<span class="number">3</span>  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//输入一个成绩   5，4，3，2，1，0  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>关于break;<br>在switch语句中，如果case 没有break,那么将会穿透   </p>
</blockquote>
<blockquote>
<p>解决问题<br>输入月份，判断此月有多少天？<br>2:28，29<br>1，3，5，7，8，10，12:31<br>4,6,9,11:30</p>
<p>case:<br>    2,<br>    4,<br>    6,<br>    9,11</p>
<p>default:</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Switch2</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> </span><br><span class="line">	&#123;</span><br><span class="line">		Scanner s=<span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"></span><br><span class="line">		System.out.println(<span class="string">&quot;输入月份&quot;</span>);</span><br><span class="line"></span><br><span class="line">		<span class="type">int</span> month=s.nextInt();</span><br><span class="line"></span><br><span class="line">		<span class="keyword">switch</span>(month)&#123;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">				System.out.println(<span class="string">&quot;28或29天&quot;</span>);</span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">4</span>:</span><br><span class="line">			<span class="keyword">case</span> <span class="number">6</span>:</span><br><span class="line">			<span class="keyword">case</span> <span class="number">9</span>:</span><br><span class="line">			<span class="keyword">case</span> <span class="number">11</span>:</span><br><span class="line">				System.out.println(<span class="string">&quot;30天&quot;</span>);</span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">default</span>:</span><br><span class="line">				System.out.println(<span class="string">&quot;31天&quot;</span>);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>使用switch的注意事项<br>1.switch只能使用等值比较，而且对数据类型有要求（byte,short,int,char,String）<br>2.注意 case穿透   （break）<br>3.switch的结果清晰，但没有if应用的广泛   </p>
</blockquote>
<h2 id="循环"><a href="#循环" class="headerlink" title="循环"></a>循环</h2><blockquote>
<p>语法很简单，练习是关键</p>
</blockquote>
<h3 id="循环语句的三个部分"><a href="#循环语句的三个部分" class="headerlink" title="循环语句的三个部分"></a>循环语句的三个部分</h3><blockquote>
<p>1.初始化部分（1次）<br>2.条件部分（多次）<br>3.循环体部分   (多次)</p>
</blockquote>
<h3 id="java中，循环语句的分类"><a href="#java中，循环语句的分类" class="headerlink" title="java中，循环语句的分类"></a>java中，循环语句的分类</h3><blockquote>
<p>1.while<br>2.do-while<br>3.for</p>
</blockquote>
<h3 id="while语句"><a href="#while语句" class="headerlink" title="while语句"></a>while语句</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法</span></span><br><span class="line">[初始化语句]</span><br><span class="line"><span class="keyword">while</span>(表达式)&#123;</span><br><span class="line">	循环体语句;</span><br><span class="line">&#125;</span><br><span class="line">...</span><br></pre></td></tr></table></figure>

<blockquote>
<p>1+2+3+4…..+100;</p>
<p>int sum&#x3D;0;&#x2F;&#x2F;定义一个变量   用来存储累加的和</p>
<p>int i&#x3D;1;<br>sum+&#x3D;i;(1.2,3,4,5,5.6,7)</p>
</blockquote>
<blockquote>
<p>盈盈为了考验令狐冲夺冠的决心，要他说一百遍“我能行！”;<br>1+…100;</p>
</blockquote>
<h3 id="死循环"><a href="#死循环" class="headerlink" title="死循环"></a>死循环</h3><blockquote>
<p>死循环：无法结束的循环被称为死循环   </p>
</blockquote>
<h3 id="变量的作用域"><a href="#变量的作用域" class="headerlink" title="变量的作用域"></a>变量的作用域</h3><p>内层可以使用外层的变量，外层不能使用内层的变量</p>
<h3 id="do-while"><a href="#do-while" class="headerlink" title="do-while"></a>do-while</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//do-while循环</span></span><br><span class="line">[初使化变量]</span><br><span class="line"><span class="keyword">do</span>&#123;</span><br><span class="line">	循环体  </span><br><span class="line">&#125;<span class="keyword">while</span>(布尔表达式);</span><br><span class="line"></span><br><span class="line">特点：至少进入一次循环体  </span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//猜数游戏</span></span><br><span class="line">Random r=<span class="keyword">new</span> <span class="title class_">Random</span>();</span><br><span class="line"><span class="type">int</span> n=r.nextInt(<span class="number">10</span>);<span class="comment">//产生一个随机数，（整数）</span></span><br><span class="line"><span class="type">int</span> i=<span class="number">0</span>;<span class="comment">//代表用户猜的那个数值</span></span><br><span class="line"><span class="keyword">do</span>&#123;</span><br><span class="line">	<span class="comment">//猜数  </span></span><br><span class="line">&#125;<span class="keyword">while</span>(n!=i)</span><br><span class="line"></span><br><span class="line"><span class="comment">//计算一下，用户用了几次机会  </span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">GuessNumber</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> </span><br><span class="line">	&#123;</span><br><span class="line">		Random r=<span class="keyword">new</span> <span class="title class_">Random</span>();<span class="comment">//创建一个随机数生成器  </span></span><br><span class="line">		Scanner s=<span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);<span class="comment">//创建一个扫描器，用来接收用户猜的数字</span></span><br><span class="line">		</span><br><span class="line">		<span class="type">int</span> n=r.nextInt(<span class="number">100</span>)+<span class="number">1</span>;<span class="comment">//获得一个随机数  </span></span><br><span class="line"></span><br><span class="line">		<span class="type">int</span> i=<span class="number">0</span>;<span class="comment">//i代表用户每次猜的那个数，如果i==n,说明猜对了  </span></span><br><span class="line"></span><br><span class="line">		<span class="keyword">do</span>&#123;</span><br><span class="line">			<span class="comment">//每次猜数</span></span><br><span class="line">			System.out.println(<span class="string">&quot;说出一个数字&quot;</span>);</span><br><span class="line">			i=s.nextInt();</span><br><span class="line"></span><br><span class="line">			<span class="keyword">if</span>(i&gt;n)&#123;</span><br><span class="line">				System.out.println(<span class="string">&quot;高了&quot;</span>);</span><br><span class="line">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(i&lt;n)&#123;</span><br><span class="line">				System.out.println(<span class="string">&quot;低了&quot;</span>);</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;<span class="keyword">while</span>(i!=n);</span><br><span class="line"></span><br><span class="line">		System.out.println(<span class="string">&quot;你猜对了，这个数就是：&quot;</span>+n);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="for循环"><a href="#for循环" class="headerlink" title="for循环"></a>for循环</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(初始化变量;条件表达式;循环体的最后一个表达式  )&#123;</span><br><span class="line">	循环体  </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//特点：非常适用于已知循环次数的程序  </span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> sum=<span class="number">0</span>;</span><br><span class="line"><span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i&lt;<span class="number">100</span>;i++)&#123;</span><br><span class="line">	sum+=i;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//1.int i=0;</span></span><br><span class="line"><span class="comment">//2( i&lt;100;  sum+=i; i++)</span></span><br></pre></td></tr></table></figure>

<h3 id="break-与-continue"><a href="#break-与-continue" class="headerlink" title="break 与 continue"></a>break 与 continue</h3><blockquote>
<p>break与continue都是关键字，可以在循环体中使用   （for,while,do-while）</p>
<p>break:结束当前循环（退出循环）<br>continue:结束当次循环，进入下一次循环判断   </p>
</blockquote>
<h3 id="嵌套循环"><a href="#嵌套循环" class="headerlink" title="嵌套循环"></a>嵌套循环</h3><blockquote>
<p>语法结构：<br>    在一个循环体中，包含另外一个循环语句，这种结构就是嵌套循环   </p>
</blockquote>
<h3 id="循环中的算法"><a href="#循环中的算法" class="headerlink" title="循环中的算法"></a>循环中的算法</h3><blockquote>
<p>暴力（穷举）：数字，字母，特殊字符   </p>
<p>顺推：已知条件推结果</p>
<p>逆推：已知结果推条件   </p>
</blockquote>
<h2 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h2><h3 id="数组的定义"><a href="#数组的定义" class="headerlink" title="数组的定义"></a>数组的定义</h3><blockquote>
<p>1.数组是一种引用数据类型，它可以存储多个相同类型的数据   </p>
<p>2.数组的长度一旦定义，不能改变</p>
<p>3.数组中的元素可以通过下标来访问，下标的取值范围是0~长度-1</p>
</blockquote>
<h3 id="数组-1"><a href="#数组-1" class="headerlink" title="数组"></a>数组</h3><p>数组元素的初始化   </p>
<blockquote>
<p>动态：创建数组后，为元素分别赋值</p>
<p>静态：创建数组的同时，为元素赋值   </p>
</blockquote>
<p>for each</p>
<blockquote>
<p>增强的for循环   </p>
<p>作用：遍历集合中的数据   </p>
<p>语法：</p>
<p>for(数据类型 变量:数组名){</p>
<p>}</p>
<p>将数组中的元素转成字符串   </p>
<p>Arrays.toString(数组)</p>
</blockquote>
<h3 id="内存模型"><a href="#内存模型" class="headerlink" title="内存模型"></a>内存模型</h3><p>java虚拟机将内容主要分为两个区域，分别是栈和堆</p>
<blockquote>
<p>基本数据类型，存在栈中   </p>
<p>int i&#x3D;9;</p>
<p>基本数据类型变量存储的是数据本身   </p>
</blockquote>
<blockquote>
<p>引用类型是存储在堆中的   </p>
<p>引用类型有数组，类，接口   </p>
<p>int[] a&#x3D;new int[5];</p>
</blockquote>
<h2 id="排序及二维数组"><a href="#排序及二维数组" class="headerlink" title="排序及二维数组"></a>排序及二维数组</h2><h3 id="算法"><a href="#算法" class="headerlink" title="算法"></a>算法</h3><blockquote>
<p>什么是算法：</p>
<p>其实就是解决问题？</p>
<p>如何衡量算法优劣？</p>
<p>时间</p>
<p>空间</p>
<p>时间复杂度：大O表示法   </p>
<p>O(1):固定次数，常数</p>
<p>O(logn):二分</p>
<p>O(n):一层循环</p>
<p>O(n方):二层循环</p>
<p>O(n的立方):三层循环</p>
<p>O(2的n次幂)：</p>
<p>O(n!):</p>
</blockquote>
<h3 id="排序"><a href="#排序" class="headerlink" title="排序"></a>排序</h3><blockquote>
<p>排序是最常的算法   </p>
<p>直接选择排序？</p>
<p>冒泡排序？</p>
<p>未排序，已排序   </p>
<p>相邻比较并交换。整个的过程就像冒水泡一样   </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="comment">//冒泡排序</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">BubbleSort</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int</span>[] nums=&#123;<span class="number">12</span>,<span class="number">45</span>,<span class="number">78</span>,<span class="number">5</span>,<span class="number">75</span>,<span class="number">33</span>,<span class="number">23</span>,<span class="number">47</span>&#125;;</span><br><span class="line">        <span class="type">int</span> temp=<span class="number">0</span>;</span><br><span class="line"><span class="comment">//循环n-1次  </span></span><br><span class="line">        <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i&lt;nums.length-<span class="number">1</span>;i++)&#123;</span><br><span class="line"><span class="comment">//通过冒泡，每次从未排序堆中选一个最大的，放在已排序堆中</span></span><br><span class="line">            <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">0</span>;j&lt;nums.length-<span class="number">1</span>-i;j++)&#123;</span><br><span class="line"><span class="comment">//交换</span></span><br><span class="line">                <span class="keyword">if</span>(nums[j]&gt;nums[j+<span class="number">1</span>])&#123;</span><br><span class="line">                    temp=nums[j];</span><br><span class="line">                    nums[j]=nums[j+<span class="number">1</span>];</span><br><span class="line">                    nums[j+<span class="number">1</span>]=temp;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        System.out.println(Arrays.toString(nums));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="comment">//直接选择排序</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Sort3</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int</span>[] nums=&#123;<span class="number">30</span>,<span class="number">78</span>,<span class="number">90</span>,<span class="number">10</span>,<span class="number">4</span>,<span class="number">67</span>&#125;;</span><br><span class="line"><span class="comment">//将最大的元素与第一个元素进行交换   </span></span><br><span class="line"><span class="comment">//1.定义一个变量，用来存储最大元素的下标</span></span><br><span class="line">        <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i&lt;nums.length-<span class="number">1</span>;i++)&#123;</span><br><span class="line">            <span class="type">int</span> max=i;</span><br><span class="line"><span class="comment">//1.向未排序堆中找出最大的元素的下标   </span></span><br><span class="line">            <span class="keyword">for</span>(<span class="type">int</span> j=i+<span class="number">1</span>;j&lt;nums.length;j++)&#123;</span><br><span class="line">                <span class="keyword">if</span>(nums[max]&lt;nums[j])&#123;</span><br><span class="line">                    max=j;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line"><span class="comment">//2.交换   </span></span><br><span class="line">            <span class="keyword">if</span>(max!=i)&#123;</span><br><span class="line">                <span class="type">int</span> temp=nums[max];</span><br><span class="line">                nums[max]=nums[i];</span><br><span class="line">                nums[i]=temp;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        System.out.println(Arrays.toString(nums));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="二分法"><a href="#二分法" class="headerlink" title="二分法"></a>二分法</h3><blockquote>
<p>二分法，也称为折半查找法   前提是，数据一定是已排序的。</p>
<p>时间复杂度为O(logn)</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">BinarySearch</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int</span>[] nums=&#123;<span class="number">1</span>,<span class="number">3</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">9</span>,<span class="number">11</span>,<span class="number">23</span>,<span class="number">34</span>,<span class="number">56</span>,<span class="number">67</span>,<span class="number">88</span>,<span class="number">99</span>,<span class="number">100</span>&#125;;</span><br><span class="line">        Scanner s=<span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line">        System.out.println(<span class="string">&quot;请输入一个数&quot;</span>);</span><br><span class="line">        <span class="type">int</span> n=s.nextInt();</span><br><span class="line">        <span class="type">int</span> i=<span class="number">0</span>;</span><br><span class="line">        <span class="type">int</span> j=nums.length-<span class="number">1</span>;</span><br><span class="line">        <span class="type">int</span> m=<span class="number">0</span>;</span><br><span class="line"><span class="comment">//1.编写代码，完成查询，如果找到了，输出位置，否则，输出“查无此数”   </span></span><br><span class="line"><span class="comment">//2.分别使用O(n) O(logn)来解决？</span></span><br><span class="line">        <span class="keyword">while</span>(i&lt;=j)&#123;</span><br><span class="line"><span class="comment">//1.计算出中间位置   </span></span><br><span class="line">            m=(i+j)&gt;&gt;<span class="number">1</span>;</span><br><span class="line">            <span class="keyword">if</span>(n==nums[m])&#123;</span><br><span class="line">                System.out.println(<span class="string">&quot;找到了，位置是：&quot;</span>+m);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;<span class="keyword">else</span> <span class="keyword">if</span>(nums[m]&gt;n)&#123;</span><br><span class="line">                j=m-<span class="number">1</span>;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                i=m+<span class="number">1</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(i&gt;j)&#123;</span><br><span class="line">            System.out.println(<span class="string">&quot;查无此数&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">            </span><br></pre></td></tr></table></figure>

<h3 id="二位数组"><a href="#二位数组" class="headerlink" title="二位数组"></a>二位数组</h3><p>二维数组</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">java中其实没有二维数组，所谓的二维数组其实就是一个数组，只不过数组中的元素还是一个数组   </span><br><span class="line"></span><br><span class="line"><span class="type">int</span>[] nums=&#123;<span class="number">3</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>&#125;;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> nums=<span class="keyword">new</span> <span class="title class_">int3</span>;</span><br><span class="line"></span><br><span class="line">二维数组的初使化</span><br><span class="line"></span><br><span class="line">静态初使化</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> nums=&#123;&#123;<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">7</span>&#125;,&#123;<span class="number">6</span>,<span class="number">6</span>,<span class="number">6</span>&#125;,&#123;<span class="number">8</span>,<span class="number">9</span>,<span class="number">4</span>,<span class="number">3</span>&#125;&#125;;</span><br><span class="line"></span><br><span class="line">动态初使化   </span><br><span class="line"></span><br><span class="line"><span class="type">int</span> nums=<span class="keyword">new</span> <span class="title class_">int3</span>;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> nums=<span class="keyword">new</span> <span class="title class_">int3</span>;</span><br><span class="line"></span><br><span class="line">nums[<span class="number">0</span>]=<span class="keyword">new</span> <span class="title class_">int</span>[]&#123;<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">8</span>&#125;;</span><br><span class="line"></span><br><span class="line">nums[<span class="number">1</span>]=<span class="keyword">new</span> <span class="title class_">int</span>[]&#123;<span class="number">333</span>,<span class="number">56</span>&#125;;</span><br><span class="line"></span><br><span class="line">nums[<span class="number">2</span>]=<span class="keyword">new</span> <span class="title class_">int</span>[]&#123;<span class="number">4</span>,<span class="number">4</span>,<span class="number">6</span>,<span class="number">8</span>&#125;;</span><br><span class="line"></span><br><span class="line">String names=&#123;&#123;<span class="string">&quot;刘备&quot;</span>,<span class="string">&quot;张飞&quot;</span>,<span class="string">&quot;关羽&quot;</span>&#125;,&#123;<span class="string">&quot;曹操&quot;</span>&#125;,&#123;<span class="string">&quot;孙权&quot;</span>,<span class="string">&quot;周瑜&quot;</span>&#125;&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h1 id="面向对象OOP"><a href="#面向对象OOP" class="headerlink" title="面向对象OOP"></a>面向对象OOP</h1><h2 id="面向过程与面向对象"><a href="#面向过程与面向对象" class="headerlink" title="面向过程与面向对象"></a>面向过程与面向对象</h2><blockquote>
<p>面向对象，强调由谁来做<br>面向过程，强调怎么做</p>
<p>面向过程：把解决问题的步骤列出来，再逐步实现</p>
<p>面向对象：将问题域中的对象找出来，再确定它们之间的关系   </p>
</blockquote>
<p>面向对象有什么优点</p>
<blockquote>
<p>1.更容易理解<br>2.解决复杂的问题，更有优势</p>
</blockquote>
<h2 id="面向对象的基础知识"><a href="#面向对象的基础知识" class="headerlink" title="面向对象的基础知识"></a>面向对象的基础知识</h2><blockquote>
</blockquote>
<h3 id="什么是对象"><a href="#什么是对象" class="headerlink" title="什么是对象"></a>什么是对象</h3><blockquote>
<p>所有具体的事物都是对象（object）</p>
</blockquote>
<h3 id="类"><a href="#类" class="headerlink" title="类"></a>类</h3><blockquote>
<p>类是一组具有相同属性和行为的一组对象的抽象表示<br>类和对象的关系：<br>  类是对象的抽象表示<br>  对象是类的一个具体实例<br>类是抽象的，对象是具体的</p>
</blockquote>
<p>class ：</p>
<h3 id="定义类的语法"><a href="#定义类的语法" class="headerlink" title="定义类的语法"></a>定义类的语法</h3><blockquote>
<p>回顾</p>
<p>1.面向过程，面向对象的区别？</p>
<p>2.面向对象的两个重要的概念</p>
<p>对象，类   </p>
<p>3.如何定义一个类   </p>
<p>class 类名｛</p>
<p>属性   </p>
<p>方法   </p>
<p>}</p>
</blockquote>
<p>类中都应该有什么</p>
<blockquote>
<p>1.定义一个学生类型</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">student</span>&#123;</span><br><span class="line">    <span class="type">int</span> stuno;     <span class="comment">//定义类的属性</span></span><br><span class="line">    String name;</span><br><span class="line">    String sex;</span><br><span class="line">    <span class="type">int</span> age;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="方法"><a href="#方法" class="headerlink" title="方法"></a>方法</h3><blockquote>
<p>大家用过方法吗？</p>
<p>用过哪呢？</p>
<p>Random r&#x3D;new Random();</p>
<p>int i&#x3D;r.nextInt(10);</p>
<p>方法中都包括什么？</p>
<p>方法名：</p>
<p>参数：多个，每个参数都需要有类型   </p>
<p>返回值类型：</p>
<p>定义一个方法，判断是否为闰年   </p>
</blockquote>
<p>定义方法的语法?</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">返回值类型 方法名（参数列表 ）｛</span><br><span class="line">方法体   </span><br><span class="line">｝</span><br><span class="line"><span class="type">int</span> <span class="title function_">sum</span><span class="params">(<span class="type">int</span> a)</span>&#123;</span><br><span class="line">    <span class="type">int</span> s=(<span class="number">1</span>+a)*a/<span class="number">2</span>;</span><br><span class="line">    <span class="keyword">return</span> s;</span><br><span class="line">&#125;</span><br><span class="line"><span class="type">int</span> s=num(<span class="number">100</span>);</span><br><span class="line">s=num(<span class="number">50</span>);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>形参和实参的区别？</p>
<p>形参：定义方法时使用的参数，也叫形式参数   </p>
<p>实参：调用方法，传递的参数，也叫实际参数   </p>
<p>传参的过程就是赋值   即把实参赋给形参   </p>
</blockquote>
<p>return 用法</p>
<blockquote>
<p> 1.return语句 可以放在方法体中，代表返回的意思   </p>
<p>2.如果一个方法中有return 语句，return 一定作为最后一条语句来存在   </p>
<p>3.return 后的表达式的类型一定要与方法的返回值类型一致   </p>
<p>4.如果方法返回值类型为void ,那么可以省略return ,或者直接写return</p>
</blockquote>
<h3 id="内存结构"><a href="#内存结构" class="headerlink" title="内存结构"></a>内存结构</h3><p>略</p>
<h3 id="方法的传参"><a href="#方法的传参" class="headerlink" title="方法的传参"></a>方法的传参</h3><blockquote>
<p>pass by value:按值传递   </p>
<p>pass by ref:按引用传递   （引用类型）</p>
</blockquote>
<h3 id="重载（overload）"><a href="#重载（overload）" class="headerlink" title="重载（overload）"></a>重载（overload）</h3><blockquote>
<p>方法重载（overload）：同一类中，方法名相同，参数列表不同的一组方法就叫重载方法   </p>
<p>输出   </p>
<p>​       System.out.printlnEmpty();</p>
<p>​       System.out.printlnString(“hello”);</p>
<p>​       System.out.printlnInt(8);</p>
<p>参数列表的不同主要体现在三方面</p>
<p>1.数量不同</p>
<p>2.类型不同</p>
<p>3.顺序不同   </p>
<p>四件套</p>
<p>1.理解题意，考虑边界问题</p>
<p>2.找出所有解</p>
<p>3.编写代码</p>
<p>4.测试</p>
<p>leetcode</p>
</blockquote>
<h2 id="构造方法及继承"><a href="#构造方法及继承" class="headerlink" title="构造方法及继承"></a>构造方法及继承</h2><h3 id="构造方法"><a href="#构造方法" class="headerlink" title="构造方法"></a>构造方法</h3><blockquote>
<p>构造方法是一种特殊的方法<br>构造方法会给属性赋初值<br>构造方法会自动调用</p>
<p>构造方法与类同名</p>
</blockquote>
<h3 id="默认的构造方法"><a href="#默认的构造方法" class="headerlink" title="默认的构造方法"></a>默认的构造方法</h3><blockquote>
<p>1.每个类都至少有一个构造方法，如果不显式的定义，java编译器会自动为类创建一个无参的构造方法   即默</p>
<p>认的构造方法</p>
<p>2.默认的构造方法没有参数，没有方法体   </p>
<p>3.如果开发者显式的定义了构造方法，那么java编译器将不会再生成默认构造方法   </p>
</blockquote>
<h3 id="构造方法不返回值"><a href="#构造方法不返回值" class="headerlink" title="构造方法不返回值"></a>构造方法不返回值</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Student(<span class="type">int</span> no,String name,<span class="type">int</span> age)&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//构造方法前面不能加void (添加后会变成一个普通方法)</span></span><br><span class="line">(<span class="keyword">void</span>)Student()&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>默认的构造方法</p>
<h3 id="就近原则"><a href="#就近原则" class="headerlink" title="就近原则"></a>就近原则</h3><blockquote>
<p>就近原则：当访问不同作用域同名变量时   寻找最近的同名变量</p>
</blockquote>
<h3 id="this关键字"><a href="#this关键字" class="headerlink" title="this关键字"></a>this关键字</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">this</span>代表当前对象的属性引用   </span><br><span class="line"><span class="built_in">this</span> 用法：</span><br><span class="line">    <span class="built_in">this</span>.属性</span><br><span class="line">    <span class="built_in">this</span>.普通方法</span><br><span class="line">    <span class="built_in">this</span>().构造方法</span><br><span class="line">       只有在其他的构造方法中才能使用<span class="built_in">this</span>()来调用;</span><br><span class="line">       <span class="built_in">this</span>()必须位于构造方法第一条语句;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>Person p&#x3D;new Person  一共做了几件事</p>
<p>1,开辟的新的空间</p>
<p>2,调用构造方法</p>
<p>3,返回引用赋值给p</p>
</blockquote>
<h3 id="匿名块"><a href="#匿名块" class="headerlink" title="匿名块"></a>匿名块</h3><blockquote>
<p>作用：将每个构造方法中相同的代码可以写在匿名块中   匿名块中的代码一定是在构造方法之前调用。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">语法：</span><br><span class="line">&#123;</span><br><span class="line"><span class="comment">//代码   </span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="关于构造方法的小结"><a href="#关于构造方法的小结" class="headerlink" title="关于构造方法的小结"></a>关于构造方法的小结</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Person p=<span class="keyword">new</span> <span class="title class_">Person</span>(); <span class="comment">//一共做了三件事</span></span><br><span class="line"><span class="number">1.</span>在堆中开辟内存空间</span><br><span class="line"><span class="number">2.</span>调用构造方法，为属性初使化   </span><br><span class="line"><span class="number">3.</span>将引用返回给p;</span><br></pre></td></tr></table></figure>

<h2 id="包管理"><a href="#包管理" class="headerlink" title="包管理"></a>包管理</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">照片   </span><br><span class="line">d:/照片/男朋友/男朋友<span class="number">1</span>   </span><br><span class="line">/</span><br><span class="line">语法格式</span><br><span class="line"><span class="keyword">package</span> com.huayu.oop;</span><br><span class="line">导包   </span><br><span class="line"><span class="keyword">import</span> com.huayu.oop.*;</span><br><span class="line"><span class="keyword">import</span> com.huayu.oop.Person;</span><br></pre></td></tr></table></figure>



<h2 id="继承"><a href="#继承" class="headerlink" title="继承"></a>继承</h2><blockquote>
<p>继承是面向对象编程的最重要的特性之王一，它可以简化类的设计，利用的原有的类来创建新的类</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Person</span>&#123;&#125;;</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Student</span> <span class="keyword">extends</span> <span class="title class_">Person</span>&#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>关于继承的总结</p>
<p>1.java中，只支持继承</p>
<p>2.子类继承父类的属性和方法，并且可以增加新的属性和方法</p>
<p>3.使用extends关键字来继承</p>
<p>4.是否可以使用继承 ，可以通过Instanceof 来判断</p>
</blockquote>
<h3 id="方法重写"><a href="#方法重写" class="headerlink" title="方法重写"></a>方法重写</h3><blockquote>
<p>方法重写（override,overwrite）:在继承关系下，子类覆盖父类的方法覆盖时，要求方法名，参数，返回值都相同</p>
</blockquote>
<h3 id="关于继承的小结"><a href="#关于继承的小结" class="headerlink" title="关于继承的小结"></a>关于继承的小结</h3><blockquote>
<p>1.父类有的，子类一定有</p>
<p>2.父类没有的，子类可以扩展</p>
<p>3.父类有的，子类可以更改   </p>
</blockquote>
<h3 id="super关键字"><a href="#super关键字" class="headerlink" title="super关键字"></a>super关键字</h3><blockquote>
<p>super代表父类对象的引用<br>通过super关键字,再子类中可以</p>
</blockquote>
<h2 id="多态和封装"><a href="#多态和封装" class="headerlink" title="多态和封装"></a>多态和封装</h2><blockquote>
<p>面向对象的高级特性   </p>
<p>封装</p>
<p>继承 ：复用</p>
<p>多态</p>
</blockquote>
<h3 id="多态"><a href="#多态" class="headerlink" title="多态"></a>多态</h3><blockquote>
<p>多态：同一类事物，可以拥有不同的形态</p>
<p>动物：吃，喝，行走</p>
<p>狗：</p>
<p>猫：</p>
<p>蛇：</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//子类的对象可以替代父类的对象进行使用</span></span><br><span class="line">Student s=<span class="keyword">new</span> <span class="title class_">Student</span>();</span><br><span class="line">Person p=s;</span><br><span class="line">父类 s=<span class="keyword">new</span> 子类</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="编译时类型"><a href="#编译时类型" class="headerlink" title="编译时类型"></a>编译时类型</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//当我们使用多态时，定义变量时使用的类型称为编译时类型   我们在使用方法和属性时，只能使用编译时类型</span></span><br><span class="line"><span class="comment">//提供的属性和方法   </span></span><br><span class="line">Person p=<span class="keyword">new</span> <span class="title class_">Student</span>();<span class="comment">//此时，编译时类型是Person   </span></span><br><span class="line">Animal a=<span class="keyword">new</span> <span class="title class_">Dog</span>(); <span class="comment">//编译时类型是Animal</span></span><br><span class="line">a=net <span class="title function_">Cat</span><span class="params">()</span>;</span><br><span class="line">a=<span class="keyword">new</span> <span class="title class_">Fish</span>();</span><br><span class="line">a=<span class="keyword">new</span> <span class="title class_">Bird</span>();</span><br></pre></td></tr></table></figure>

<h3 id="运行时类型"><a href="#运行时类型" class="headerlink" title="运行时类型"></a>运行时类型</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//当我们调用多态的方法时，执行期间，调用的是运行时类型的方法   </span></span><br><span class="line">Animal a=<span class="keyword">new</span> <span class="title class_">Dog</span>(); <span class="comment">//编译时类型是Animal，运行时类型是Dog</span></span><br><span class="line">a=net <span class="title function_">Cat</span><span class="params">()</span>; <span class="comment">//编译时类型是Animal，运行时类型是Cat</span></span><br><span class="line">a=<span class="keyword">new</span> <span class="title class_">Fish</span>(); <span class="comment">//编译时类型是Animal，运行时类型是Fish</span></span><br><span class="line">a=<span class="keyword">new</span> <span class="title class_">Bird</span>(); <span class="comment">//编译时类型是Animal，运行时类型是Bird</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h3><blockquote>
<p>downcast:向下转型</p>
<p>upcast:向上转型</p>
<p>向上转换：直接转换无风险<br>向下转换：有风险</p>
<p>例如将，Animal转成Dog就是向下转型，向下转型有风险，建议转型前，使用instanceof来判断   否则可能</p>
<p>会产生ClassCastException（类型转换异常） 异常   </p>
</blockquote>
<h3 id="封装"><a href="#封装" class="headerlink" title="封装"></a>封装</h3><blockquote>
<p>java中，处处皆封装   主要表现在三方面？</p>
<p>1.类就是一个封装体，类中封装的属性，方法   </p>
<p>2.方法也是一种封装   （方法中封装的是代码）</p>
<p>Random r&#x3D;new Random();</p>
<p>r.nextInt(10);</p>
<p>3.通过访问修饰符可以改变访问权限</p>
</blockquote>
<h3 id="访问修饰符"><a href="#访问修饰符" class="headerlink" title="访问修饰符"></a>访问修饰符</h3><table>
<thead>
<tr>
<th align="center"></th>
<th align="center">类内部</th>
<th align="center">同包</th>
<th align="center">不同包的子类</th>
<th align="center">不同包的非子类</th>
</tr>
</thead>
<tbody><tr>
<td align="center">private</td>
<td align="center">是</td>
<td align="center">否</td>
<td align="center">否</td>
<td align="center">否</td>
</tr>
<tr>
<td align="center">default</td>
<td align="center">是</td>
<td align="center">是</td>
<td align="center">否</td>
<td align="center">否</td>
</tr>
<tr>
<td align="center">protected</td>
<td align="center">是</td>
<td align="center">是</td>
<td align="center">是</td>
<td align="center">否</td>
</tr>
<tr>
<td align="center">public</td>
<td align="center">是</td>
<td align="center">是</td>
<td align="center">是</td>
<td align="center">是</td>
</tr>
</tbody></table>
<h3 id="修饰符"><a href="#修饰符" class="headerlink" title="修饰符"></a>修饰符</h3><h4 id="final"><a href="#final" class="headerlink" title="final"></a>final</h4><blockquote>
<p>final修饰属性，类，方法<br>它可以修饰，属性，变量，参数，只能赋值一次 不能被修改<br>修饰类：不能被继承<br>修饰方法：不能被重写</p>
</blockquote>
<h4 id="static"><a href="#static" class="headerlink" title="static"></a>static</h4><blockquote>
<p>static修饰属性，说明当前属性是的类属性，只存在一份整个类共享<br>并且可以直接通过类访问。<br>属性：类属性   类名，属性名<br>方法：类方法   </p>
<p>示例   </p>
<p>定义一个学生类，为学生自动生成学号，即创建的第一个学生，学号是1，第二个学生，学号是2   </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Student</span> &#123;</span><br><span class="line">    <span class="type">int</span> stuno;</span><br><span class="line">    String name;</span><br><span class="line">    <span class="type">int</span> age;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">Student</span><span class="params">(String name, <span class="type">int</span> age)</span> &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">showInfo</span><span class="params">()</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;学号：&quot;</span> + stuno + <span class="string">&quot;,姓名：&quot;</span> + name + <span class="string">&quot;,age:&quot;</span> + age);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="type">Student</span> <span class="variable">s</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Student</span>(<span class="string">&quot;王千金&quot;</span>, <span class="number">18</span>);</span><br><span class="line">        <span class="type">Student</span> <span class="variable">s1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Student</span>(<span class="string">&quot;王万两&quot;</span>, <span class="number">18</span>);</span><br><span class="line">        <span class="type">Student</span> <span class="variable">s2</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Student</span>(<span class="string">&quot;王大锤&quot;</span>, <span class="number">19</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>方法：</p>
<p>1.被static修饰的方法被称为类方法，调用类方法时无须创建对象，可以通过 类名.方法名()来调用   </p>
<p>2.在static方法中，只能实现静态成员，不能使用非静态成员   </p>
<p>3.在static方法中，也不能使用this,super关键字   </p>
<p>static 返回值类型 方法名(){</p>
<p>&#x2F;&#x2F;方法体   </p>
<p>}</p>
</blockquote>
<h4 id="静态块"><a href="#静态块" class="headerlink" title="静态块"></a>静态块</h4><blockquote>
<p>static块</p>
<p>语法：</p>
<p>static{</p>
<p>&#x2F;&#x2F;代码   </p>
<p>}</p>
<p>什么时执行：当类加载，初使化时，会自动调用静态块中的代码，因为每个类只加载一次，因此static{}只</p>
<p>被调用一次   </p>
</blockquote>
<blockquote>
<p>加载顺序<br>静态成员和static块<br>👇<br>普通成员和非static块<br>👇<br>构造方法</p>
</blockquote>
<blockquote>
<p>加载顺寻<br>父类静态成员和static块<br>👇<br>子类静态成员和static块<br>👇<br>父类普通成员和非static块<br>👇<br>父类构造方法<br>👇<br>子类普通成员和非static块<br>👇<br>子类构造方法</p>
</blockquote>
<h4 id="单例模式"><a href="#单例模式" class="headerlink" title="单例模式"></a>单例模式</h4><blockquote>
<p>设计模式：Design partten</p>
<p>解决某些设计问题所采用的套路，有点类似于三十六计   </p>
<p>目前设计模式一共有23种   </p>
<p>一共分为三类   </p>
<p>1.创建型</p>
<p>2.结构型</p>
<p>3.行为型</p>
</blockquote>
<p><strong>单例模式：</strong>Singleton</p>
<blockquote>
<p>解决的问题：某个类，只允许产生唯一的实例   </p>
<p>解决的方法</p>
<p>1.将构造方法定义成私有   </p>
<p>2.定义一个同类型的静态的属性   </p>
<p>3.定义一个public的静态方法，用来返回唯一的实例   </p>
</blockquote>
<p><strong>单例模式 的两种类型</strong></p>
<blockquote>
<p>1.饿汉式   </p>
<p>2.懒汉式   （lazy）</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> Singleton s=<span class="keyword">new</span> <span class="title class_">Singleton</span>();</span><br><span class="line">	<span class="comment">/*String name;</span></span><br><span class="line"><span class="comment">	String time;*/</span></span><br><span class="line">	<span class="keyword">private</span> <span class="title function_">Singleton</span><span class="params">()</span>&#123;</span><br><span class="line">		<span class="comment">/*System.out.println(&quot;创建单例模式: &quot;);</span></span><br><span class="line"><span class="comment">		System.out.println(&quot;进程分别有&quot;);</span></span><br><span class="line"><span class="comment">		System.out.println(&quot;1&quot;);</span></span><br><span class="line"><span class="comment">		System.out.println(&quot;2&quot;);</span></span><br><span class="line"><span class="comment">		System.out.println(&quot;3&quot;);</span></span><br><span class="line"><span class="comment">		System.out.println(&quot;4&quot;);*/</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> Singleton <span class="title function_">getinstance</span><span class="params">()</span> &#123;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">return</span> s;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">/*public void close() &#123;</span></span><br><span class="line"><span class="comment">		System.out.println(&quot;关闭程序&quot;);</span></span><br><span class="line"><span class="comment">	&#125;	*/</span></span><br></pre></td></tr></table></figure>

<h1 id="抽象类与接口"><a href="#抽象类与接口" class="headerlink" title="抽象类与接口"></a><strong>抽象类与接口</strong></h1><h2 id="abstract"><a href="#abstract" class="headerlink" title="abstract"></a>abstract</h2><blockquote>
<p>abstract是一个修饰符</p>
<p>可以修饰方法和类<br>类：抽象类，不能被实例化<br>方法：抽象方法，让子类重写   如果子类不重写，子类方法也是抽象方法<br>抽象方法没有具体的实现   </p>
<p>抽象方法只有定义，没有方法的实现<br>如果一个类有抽象方法，那这个类一定是抽象类<br>如果子类不重写方法，那这个子类还是抽象类</p>
</blockquote>
<h2 id="接口"><a href="#接口" class="headerlink" title="接口"></a>接口</h2><blockquote>
<p>1.java中不支持继承，但通过接口，可以实现多继承的效果   </p>
<p>2.接口是一个特殊的抽象类   接口中只能有抽象方法和public static final属性   </p>
<p>3.接口使用 interface来定义   </p>
</blockquote>
<h3 id="接口与类"><a href="#接口与类" class="headerlink" title="接口与类"></a>接口与类</h3><blockquote>
<p>接口通常代表一种能力，抽象类通常代表一个概念   </p>
<p>接口：able:</p>
<p>会飞的</p>
<p>发光的</p>
<p>吃肉的</p>
<p>抽象类：</p>
<p>动物</p>
<p>交通工具   </p>
<p>图形   </p>
<p>找你妹   </p>
<p>发光   </p>
<p>会飞的   </p>
<p>带尖的   </p>
<p>交通工具   </p>
<p>飞机   </p>
<p>会飞的 a&#x3D;new Plan();</p>
<p>&#x3D;new 天使();</p>
<p>&#x3D;new 蝙蝠();</p>
<p>&#x3D;new 萤火虫();</p>
</blockquote>
<h3 id="接口与抽象类的区别"><a href="#接口与抽象类的区别" class="headerlink" title="接口与抽象类的区别"></a><strong>接口与抽象类的区别</strong></h3><blockquote>
<p>1.接口是一个特殊的抽象类，只有public static final 属性及抽象方法   </p>
<p>2.一个类只能有一个父类，但一个类可以同时实现多个接口   </p>
<p>3.类和类之间是单继承 ，但接口和接口之间可以多继承</p>
<p>interface C extends A,B</p>
<p>4.抽象类通常表示一个概念，而接口则表示一种能力   </p>
</blockquote>
<h3 id="类和类之间的关系"><a href="#类和类之间的关系" class="headerlink" title="类和类之间的关系"></a><strong>类和类之间的关系</strong></h3><blockquote>
<p>主要有三种   </p>
<p>1.继承</p>
<p>2.关联</p>
<p>3.依赖   </p>
<p>关联又可以细分为</p>
<p>1.聚合</p>
<p>2.组合</p>
</blockquote>
<h4 id="继承-1"><a href="#继承-1" class="headerlink" title="继承"></a>继承</h4><blockquote>
<p>子类拥有父类的属性和方法   </p>
<p>判断两个类是否是继承关系 is 即 子类 is 父类   </p>
<p>代码： class 子类 extends 父类｛｝</p>
</blockquote>
<h4 id="实现"><a href="#实现" class="headerlink" title="实现"></a>实现</h4><blockquote>
<p>一个类可以实现多个接口   </p>
<p>代码： class 类 implements 接口   </p>
</blockquote>
<h4 id="依赖"><a href="#依赖" class="headerlink" title="依赖"></a>依赖</h4><blockquote>
<p>两个类之间关系是临时发生的，即做某一件事时才产生联系，这种关系就是依赖   </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">判断方法 ： use;</span><br><span class="line">代码：</span><br><span class="line">两种形式</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Person</span>&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">eat</span><span class="params">()</span>&#123;</span><br><span class="line">        Spoon s=<span class="keyword">new</span> <span class="title class_">Spoon</span>();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">attack</span><span class="params">(Weapon w)</span>&#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="关联"><a href="#关联" class="headerlink" title="关联"></a>关联</h4><blockquote>
<p>关联：一种强依赖，比依赖的关系更强，是一种稳定的关系   </p>
<p>判断： has</p>
<p>代码：作为别外一个类的属性来存在   </p>
</blockquote>
<h4 id="聚合"><a href="#聚合" class="headerlink" title="聚合"></a>聚合</h4><blockquote>
<p>聚合是关联的一种特例，体现整体和局部的关系    整体和局部之间没有共同的生命周期   </p>
</blockquote>
<h4 id="组合"><a href="#组合" class="headerlink" title="组合"></a>组合</h4><blockquote>
<p>聚合是关联的一种特例，体现整体和局部的关系    整体和局部之间有共同的生命周期   </p>
</blockquote>
<h4 id="设计思想"><a href="#设计思想" class="headerlink" title="设计思想"></a>设计思想</h4><blockquote>
<p>高内聚，低耦合   </p>
</blockquote>
<h3 id="内部类"><a href="#内部类" class="headerlink" title="内部类"></a>内部类</h3><p>可以将类的定义放在其它的类中，这种类叫内部类   </p>
<p>内部类一共有四种，分别是</p>
<ol>
<li><p>静态内部类</p>
</li>
<li><p>成员内部类</p>
</li>
<li><p>匿名内部类</p>
</li>
<li><p>方法内部类</p>
</li>
</ol>
<h4 id="静态内部类"><a href="#静态内部类" class="headerlink" title="静态内部类"></a>静态内部类</h4><p>静态内部类可以使用外部类的静态成员</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">A</span> &#123;</span><br><span class="line">    <span class="keyword">static</span> <span class="type">int</span> a=<span class="number">9</span>;</span><br><span class="line">    String name=<span class="string">&quot;人&quot;</span>;</span><br><span class="line">    <span class="comment">//静态内部类</span></span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">B</span>&#123;</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">getB</span><span class="params">()</span> &#123;System.out.println(a);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestA</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line"><span class="comment">//创建一个内部类的对象   </span></span><br><span class="line">        A.B b=<span class="keyword">new</span> <span class="title class_">A</span>.B();</span><br><span class="line">        b.getB();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="成员内部类"><a href="#成员内部类" class="headerlink" title="成员内部类"></a>成员内部类</h4><p>在一个类的内部定义另外一个类，内部类可以使用外部类的非静态成员</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Outer</span> &#123;</span><br><span class="line">    String name=<span class="string">&quot;outer&quot;</span>;</span><br><span class="line">    <span class="keyword">class</span> <span class="title class_">Inner</span>&#123;</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">getInner</span><span class="params">()</span> &#123;</span><br><span class="line">            System.out.println(name);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestA</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line"><span class="comment">//创建一个外部类的对象   </span></span><br><span class="line">        Outer o=<span class="keyword">new</span> <span class="title class_">Outer</span>();</span><br><span class="line"><span class="comment">//创建o的内部类对象</span></span><br><span class="line">        Outer.Inner i=o.<span class="keyword">new</span> <span class="title class_">Inner</span>();</span><br><span class="line">        i.getInner();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="方法内部类"><a href="#方法内部类" class="headerlink" title="方法内部类"></a>方法内部类</h4><h4 id="匿名内部类"><a href="#匿名内部类" class="headerlink" title="匿名内部类"></a>匿名内部类</h4><p>有时，我们定义了一个内部类，使用这个内部类时，只实例一个对象   此时，就可以将定义类和实例化</p>
<p>对象，两个操作合到一起，这个就是匿名内部类</p>
<p>使用匿名类的条件是，此类必须实现一个接口或继承一个抽象类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>定义一个类</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">A</span>()&#123;</span><br><span class="line">&#125;</span><br><span class="line"><span class="number">2.</span>只实体化一次</span><br><span class="line">A a=<span class="keyword">new</span> <span class="title class_">A</span>();</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Usb u=<span class="keyword">new</span> <span class="title class_">Usb</span>() &#123;</span><br><span class="line">     <span class="meta">@Override</span></span><br><span class="line">     <span class="keyword">public</span> String <span class="title function_">getData</span><span class="params">()</span> &#123;</span><br><span class="line">     <span class="comment">// TODO Auto-generated method stub</span></span><br><span class="line">         <span class="keyword">return</span> <span class="string">&quot;这就是匿名内部类，看着有点不舒服。&quot;</span>;</span><br><span class="line">     &#125;</span><br><span class="line">&#125;;</span><br><span class="line">c.connect(u);</span><br></pre></td></tr></table></figure>

<h1 id="常用类"><a href="#常用类" class="headerlink" title="常用类"></a>常用类</h1><h2 id="lang包"><a href="#lang包" class="headerlink" title="lang包"></a>lang包</h2><blockquote>
<p>lang是java中使用最广泛的包，全称是java.lang  此包不需要手动导入，即可使用此包中的所有类   </p>
<p>此包中常用的类有   </p>
<p>System</p>
<p>Object</p>
<p>包装类</p>
<p>Math</p>
<p>字符串   </p>
<p>Thread等</p>
</blockquote>
<h2 id="System类"><a href="#System类" class="headerlink" title="System类"></a>System类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//System 类包含一些有用的类字段和方法。它不能被实例化。 final修饰的类不能被继承</span></span><br><span class="line"><span class="comment">//常用方法：</span></span><br><span class="line">System.out.println();</span><br><span class="line">System.err.println();</span><br><span class="line">System.in;</span><br><span class="line">System.exit(<span class="number">0</span>);</span><br><span class="line">System.arraycopy()</span><br><span class="line">System.gc()</span><br><span class="line">System.currentTimeMillis()</span><br></pre></td></tr></table></figure>

<h2 id="包装类"><a href="#包装类" class="headerlink" title="包装类"></a>包装类</h2><blockquote>
<p>java,为每个基本数据类型都定义了与之对对就的类，这些类就叫包装类   </p>
<p>Boolean</p>
<p>Byte,Short,Integer,Long</p>
<p>Float,Double</p>
<p>Character</p>
<p>包装类与基本数据类型是可以相互转换的   </p>
<p>基本数据类型-》包装类 ：装包</p>
<p>包装-》基本数据类型： 拆包   </p>
</blockquote>
<h2 id="Math"><a href="#Math" class="headerlink" title="Math"></a>Math</h2><blockquote>
<p>Math类：包含了所有用于几何和三角的浮点运算方法。Math类是final的，其中所有方法都是static的。</p>
</blockquote>
<h2 id="object类"><a href="#object类" class="headerlink" title="object类"></a>object类</h2><blockquote>
<p>Object类是所有类的类的父类   此类中下定义所有类都拥有的方法   </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">equals():比较</span><br><span class="line">toString():转成字符串</span><br><span class="line">hashcode():哈希码</span><br><span class="line">getClass():获得当前对象的类   </span><br><span class="line">clone():克隆   </span><br><span class="line">finalize():垃圾回收前执行的方法   </span><br><span class="line">notify()</span><br><span class="line">notifyAll();</span><br><span class="line">wait();</span><br></pre></td></tr></table></figure>

<h3 id="hashcode方法"><a href="#hashcode方法" class="headerlink" title="hashcode方法"></a>hashcode方法</h3><blockquote>
<p>hashcode是一个int值   </p>
<p>即可将任何长度的对象转换成固定长度的数字   </p>
<p>hashcode的协定   </p>
<p>1.如一个对象不改变，那么多次调用hashcode()方法，返回的结果应该相同   </p>
<p>2.如果两个对象相等（equals()），那么两个对象的hashcode()一定相等</p>
<p>3.如果两对象不相等，那么hashcode也有可能相等，设计时，尽量不相等   </p>
</blockquote>
<h3 id="equals方法"><a href="#equals方法" class="headerlink" title="equals方法"></a>equals方法</h3><blockquote>
<p>boolean equals(Object obj);</p>
<p>四个特性   </p>
<p>1.自反性:a.equals(a);  true</p>
<p>2.对称性:a.equals(b)&#x3D;&#x3D;b.equals(a);</p>
<p>3.传递性:a.equals(b)&#x3D;true,b.equals(c)&#x3D;true,那么 a.equals(c)&#x3D;true</p>
<p>4.一致性:a.equasl(b)的值，多次调用时，应该相同   （前提是，a和b都不改变）</p>
<p>另外 a.equals(null),永远为false</p>
</blockquote>
<h3 id="toString方法"><a href="#toString方法" class="headerlink" title="toString方法"></a><em>toString</em>方法</h3><blockquote>
<p>将对象转成String   </p>
<p>注意：</p>
<p>1.如果不重写，那么将会调用父类的方法，内容是 类名@hashcode()的十六进制   </p>
<p>2.当调用System.out.println(s)方法，会自动调用s.toString()方法   </p>
</blockquote>
<h3 id="getClass-方法"><a href="#getClass-方法" class="headerlink" title="**getClass()**方法"></a>**getClass()**方法</h3><blockquote>
<p>获得对象的类   Class 即，所用同类型的对象返回的是同一个类   </p>
</blockquote>
<h3 id="String-类"><a href="#String-类" class="headerlink" title="String 类"></a>String 类</h3><blockquote>
<p>字符串   Java是常用的类<br>字符串的特点<br>1.字符串是常量，不能改变<br>2.为了提升使用率，java对字符串进行了优化处理，即字符串池（String Pool）</p>
</blockquote>
<p>常用的方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">length</span><span class="params">()</span>:返回字符串的长度</span><br><span class="line"><span class="type">int</span> <span class="title function_">indexOf</span><span class="params">(<span class="type">int</span>)</span>:返回某个字符位于串中的位置（下标）</span><br><span class="line"><span class="type">int</span> <span class="title function_">lastIndexOf</span><span class="params">(String)</span>:查找最后一个指定子串的位置   </span><br><span class="line"><span class="type">boolean</span> <span class="title function_">isEmpty</span><span class="params">()</span>:判断某个字符串是否为空</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">startsWith</span><span class="params">(String)</span>:是否以某个字符串开头</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">endsWith</span><span class="params">(String)</span>:是否以某个字符串结尾</span><br><span class="line">String <span class="title function_">toUpperCase</span><span class="params">()</span>:转成大写</span><br><span class="line">String <span class="title function_">toLowerCase</span><span class="params">()</span>:转成小写   </span><br><span class="line">String <span class="title function_">trim</span><span class="params">()</span>:返回一个去掉前后空格的新串   </span><br><span class="line">String[] split(String);拆分字符串</span><br><span class="line"><span class="type">char</span> <span class="title function_">charAt</span><span class="params">(<span class="type">int</span>)</span>:根据索引找字符   </span><br><span class="line">String <span class="title function_">replaceAll</span><span class="params">(String a,String b)</span>:将字符串中的a都替换成b,并返回一个新的字符串</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">contains</span><span class="params">(String)</span>:是否包含另外一个子串</span><br></pre></td></tr></table></figure>

<h3 id="字符串类"><a href="#字符串类" class="headerlink" title="字符串类"></a>字符串类</h3><h4 id="字符串比较方法"><a href="#字符串比较方法" class="headerlink" title="字符串比较方法"></a>字符串比较方法</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">boolean</span> <span class="title function_">equals</span><span class="params">(String)</span> 比较</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">equalsIgnoreCase</span><span class="params">(String)</span> 比较（忽略大小写（英文））</span><br><span class="line"><span class="type">int</span> <span class="title function_">compareto</span><span class="params">(String)</span>  与另一个字符串比较大小</span><br><span class="line"><span class="type">int</span> <span class="title function_">comparetoignoreCase</span><span class="params">()</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="字符串池"><a href="#字符串池" class="headerlink" title="字符串池"></a>字符串池</h4><blockquote>
<p>因为String是java最常用的类，同时此类是常量（一旦定义，不能改变），因此，为了提高效率（节省内存），java中使用字符串池   </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">String s=<span class="string">&quot;hello&quot;</span>; </span><br><span class="line">String s1=<span class="string">&quot;hello&quot;</span>;</span><br><span class="line">String s2=<span class="string">&quot;hello&quot;</span>; </span><br><span class="line">String s3=<span class="string">&quot;hello&quot;</span>;</span><br></pre></td></tr></table></figure>

<h4 id="字符串转换"><a href="#字符串转换" class="headerlink" title="字符串转换"></a>字符串转换</h4><blockquote>
<p>不同的类型之间是否能转换？</p>
<p>1 基本类型 （可转）c<br>2 不同类之间 需要有继承关系才能转<br>3 如果两个类型之间没有继承关系，有时也可以通过一些方法转换<br>integer parseInt()</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">String s=<span class="string">&quot;123&quot;</span>;</span><br><span class="line"><span class="comment">//将String,s转成int类型</span></span><br><span class="line"><span class="type">int</span> i=Integer.parseInt(s);</span><br><span class="line">System.out.println(i);</span><br><span class="line"><span class="comment">//将int 类型的i转换成字符串</span></span><br><span class="line">String s2=String.valueOf(i);</span><br></pre></td></tr></table></figure>

<h4 id="StringBuffer"><a href="#StringBuffer" class="headerlink" title="StringBuffer"></a><strong>StringBuffer</strong></h4><blockquote>
<p>1.StringBuffer是字符串缓冲区，与String不同，内容是可以修改的   </p>
<p>2.StringBuffer支持链式编程</p>
<p>3.与StringBuilder不同，它是线程安全的   </p>
<p>4.StringBuffer与String是可以转换的</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">StringBuffer-&gt;String; sb.toString();</span><br><span class="line">String-&gt;StringBuffer： StringBuffer sb=<span class="keyword">new</span> <span class="title class_">StringBuffer</span>(String);</span><br></pre></td></tr></table></figure>

<p>常用方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">StringBuffer <span class="title function_">append</span><span class="params">()</span>:追加</span><br><span class="line">StringBuffer <span class="title function_">insert</span><span class="params">()</span>:插入</span><br><span class="line">StringBuffer <span class="title function_">delete</span><span class="params">(start,end)</span>:删除指定的子串</span><br><span class="line">StringBuffer <span class="title function_">repalace</span><span class="params">(start,end,str)</span>:将指定位置的字符串替换成str</span><br><span class="line">StringBuffer <span class="title function_">reverse</span><span class="params">()</span>:翻转字符串</span><br></pre></td></tr></table></figure>

<h4 id="StringBuilder"><a href="#StringBuilder" class="headerlink" title="StringBuilder"></a><strong>StringBuilder</strong></h4><blockquote>
<p>与StringBuffer基本相同，只是线程不安全   </p>
</blockquote>
<h1 id="异常"><a href="#异常" class="headerlink" title="异常"></a>异常</h1><h2 id="异常概念"><a href="#异常概念" class="headerlink" title="异常概念"></a><strong>异常概念</strong></h2><blockquote>
<p>错误主要发生有两种<br>1 编译时发生错误<br>2 运行时错误 叫做异常 </p>
<p>java的异常分为两类<br>1 error jvm内部错误、资源耗尽<br>2 exception 其他编程错误或偶然的外在因素</p>
</blockquote>
<h2 id="异常的体系结构"><a href="#异常的体系结构" class="headerlink" title="异常的体系结构"></a><strong>异常的体系结构</strong></h2><blockquote>
<p>Throwable<br>Error:错误<br>Exception:异常<br>RuntimeException:运行时异常<br>NullPointerException:空指针异常<br>ClassCastException:类型转换异常<br>ArrayIndexOutOfBoundsException:数组下标越界<br>ArithmeticException:数字异常<br>受检查异常   </p>
</blockquote>
<h2 id="异常处理"><a href="#异常处理" class="headerlink" title="异常处理"></a>异常处理</h2><blockquote>
<p>java中处理异常的机制是：抓抛模型   </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span>-<span class="keyword">catch</span>-<span class="keyword">finally</span></span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line"><span class="comment">//代码1;</span></span><br><span class="line"><span class="comment">//代码2   出现exceptin2;</span></span><br><span class="line"><span class="comment">//代码3：出现exception3;</span></span><br><span class="line">        &#125;<span class="keyword">catch</span>(Exception1 e)&#123;</span><br><span class="line"><span class="comment">//处理代码1</span></span><br><span class="line">        &#125;<span class="keyword">catch</span>(Exception2 e2)&#123;</span><br><span class="line"><span class="comment">//处理代码2</span></span><br><span class="line">        &#125;<span class="keyword">finally</span>&#123;</span><br><span class="line"><span class="comment">//finally</span></span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure>

<h2 id="异常分类"><a href="#异常分类" class="headerlink" title="异常分类"></a>异常分类</h2><blockquote>
<p>1 运行时异常 runtimeException类和其子类<br>2 受检查异常 非runtimException</p>
<p>区别：<br>运行时异常编译时可以不处理<br>受检查异常必须得处理</p>
</blockquote>
<h2 id="throws"><a href="#throws" class="headerlink" title="throws"></a>throws</h2><blockquote>
<p>当我们定义一个方法时，如果正确调用，可以返回一个结果，如果错误的调用，则应该抛出一个异常，这时，</p>
<p>可以使用throws来抛出某种异常的类型   </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="type">double</span> <span class="title function_">getCircleArea</span><span class="params">(<span class="type">double</span> r)</span> thrwos Exception&#123;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//MyArray; 10,11</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">int</span> <span class="title function_">get</span><span class="params">(<span class="type">int</span> index)</span> <span class="keyword">throws</span> ArrayIndexOutOfBoundsException&#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="throw关键字"><a href="#throw关键字" class="headerlink" title="throw关键字"></a>throw关键字</h2><blockquote>
<p>throw代表：手动抛出一个异常对象   格式是   </p>
<p>throw new Excpetion();</p>
<p>throw主要用在方法中   throw有点类似return </p>
</blockquote>
<h2 id="throw和throws的区别"><a href="#throw和throws的区别" class="headerlink" title="throw和throws的区别"></a>throw和throws的区别</h2><blockquote>
<p>throws与throw的区别</p>
<p>1.throws放在方法后，说明此方法可能抛出某种类型的异常   </p>
<p>2.throws后，放的是异常类型   </p>
<p>2.throw 放在方法体中，throw后面放置的是异常对象，说明要手动抛出一个异常   </p>
</blockquote>
<h1 id="工具类"><a href="#工具类" class="headerlink" title="工具类"></a>工具类</h1><blockquote>
<p>java.util包，被称为工具包，也是java最常用的一个包</p>
<p>此包中主要有集合框架，日期，编码解码，国际化等</p>
</blockquote>
<h2 id="random类"><a href="#random类" class="headerlink" title="random类"></a>random类</h2><blockquote>
<p>Random类是随机数生成器，提供了很多用于生成各种类型的随机数的方法</p>
</blockquote>
<h2 id="Date-类"><a href="#Date-类" class="headerlink" title="Date 类"></a>Date 类</h2><blockquote>
<p>Date类主用来存储时间，精确到毫秒，内部是通过一个long值来进行存储的</p>
</blockquote>
<h2 id="Calendar"><a href="#Calendar" class="headerlink" title="Calendar"></a><strong>Calendar</strong></h2><blockquote>
<p>日历类：主要用来处理时间，例如，获取时间的某个部分，改变时间的某个部分   对时间进行加减操作等 </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>实例化   </span><br><span class="line">Calendar c=Calendar.getInstance();</span><br><span class="line"><span class="number">2.</span>Date与Calendar的转换</span><br><span class="line">Calendar-&gt;Date c.getTime();</span><br><span class="line">date-&gt;Calendar c.setTime(date);</span><br><span class="line"><span class="number">3.</span>操作时间</span><br><span class="line">获得某个部分   </span><br><span class="line"><span class="type">int</span> <span class="title function_">get</span><span class="params">(<span class="type">int</span> )</span></span><br><span class="line">Calendar.YEAR=<span class="number">1</span>;</span><br></pre></td></tr></table></figure>

<h2 id="SimpleDateFormat"><a href="#SimpleDateFormat" class="headerlink" title="SimpleDateFormat"></a><strong>SimpleDateFormat</strong></h2><blockquote>
<p>SimpleDateFormat类是日期格式化的类，可以用来将指定格式的之符串转成Date，也可以将Date转换成指</p>
<p>定格式的字符串   </p>
<p>用法</p>
<p>1.先实例化一个对象</p>
<p>​     SimpleDateFormat sdf&#x3D;new SimpleDateFormat(“yyyy-MM-dd”);</p>
<p>2.使用 parse方法将字符串转成日期</p>
<p>​     Date d&#x3D;sdf.parse(str);</p>
<p>3.使用format方法将日期转成字符串</p>
<p>​     String str&#x3D;sdf.format(data);</p>
</blockquote>
<h1 id="集合框架"><a href="#集合框架" class="headerlink" title="集合框架"></a>集合框架</h1><h2 id="集合框架-1"><a href="#集合框架-1" class="headerlink" title="集合框架"></a>集合框架</h2><blockquote>
<p>集合：集合也被称为容器，也是一个对象，此对象中可以管理其它的对象（element）元素   例如数组就是一</p>
<p>个集合   </p>
<p>集合框架：java中给我提供了很多集合类，接口和算法类，作为一个整体，被称为集合框架</p>
</blockquote>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/25/4736ba1bd8ccacc3.png"></p>
<p>集合框架有两个顶层接口，所有的集合类都是这两个接口的实现</p>
<h2 id="Collection接口"><a href="#Collection接口" class="headerlink" title="Collection接口"></a><strong>Collection</strong>接口</h2><blockquote>
<p>1.是集合框架的顶层接口之一，没有直接的实现类   </p>
<p>2.Collection有三个子接口，分别是List,Set,Queue;</p>
<p>3.三个子接口的特点如下   </p>
<p>List:有序（有索引），可重复   </p>
<p>Set:无序，不可重复   </p>
<p>Queue:先进先出</p>
</blockquote>
<p>Collection接口应该有什么方法？</p>
<blockquote>
<p>CURD</p>
<p>boolean add(E):增加一个元素</p>
<p>boolean addAll(Collection):增加多个元素</p>
<p>void clear():清空</p>
<p>boolean isEmpty():是否为空</p>
<p>int size():返回元素的个数</p>
<p>boolean remove(E):删除一个元素</p>
<p>boolean removeAll(Collection):删除多个元素</p>
<p>boolean retainAll(Collection):保留多个元素</p>
<p>boolean contains(E):是否包含某个元素</p>
<p>boolean containsAll(Collection):是否包含某些元素</p>
<p>Object[] toArray():将集合中的元素转成数组返回</p>
</blockquote>
<p>所有集合类中存储的不是对象本身，而是一个引用而已</p>
<h2 id="泛型"><a href="#泛型" class="headerlink" title="泛型"></a>泛型</h2><blockquote>
<p>泛型指的是数据类型的参数化   </p>
<p>泛型可以解决两个问题</p>
<p>1.类型安全检查</p>
<p>2.消除强制类型转换</p>
<p>java中，集合框架中的集合类都支持泛型</p>
</blockquote>
<p>如何使用</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">List&lt;Person&gt; list=<span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;Person&gt;();</span><br></pre></td></tr></table></figure>

<h2 id="算法类"><a href="#算法类" class="headerlink" title="算法类"></a>算法类</h2><blockquote>
<p>集合框架中除了提供接口和实现类之外，还提供用于处理集合的算法类，算法类主要有</p>
<p>Collections:用于处理集合的算法类   </p>
<p>Arrays:用于处理数组的算法类   </p>
</blockquote>
<p>Collections常用的方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">sort</span><span class="params">(List)</span>:对List中的元素按自然顺序进行排序   </span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">reverse</span><span class="params">(List)</span>:翻转集合中元素</span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">shuffle</span><span class="params">(List)</span>:洗牌   （打乱顺序）</span><br><span class="line"><span class="keyword">static</span> E <span class="title function_">max</span><span class="params">(Collection)</span>:获取最大的元素</span><br><span class="line"><span class="keyword">static</span> E <span class="title function_">min</span><span class="params">(Collection)</span>:获取最小的元素   </span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">addAll</span><span class="params">(Collection coll,T...t)</span>:向coll中增加多个元素   </span><br><span class="line"><span class="keyword">static</span> <span class="type">int</span> <span class="title function_">binarySearch</span><span class="params">(List)</span>:二分查找   </span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">copy</span><span class="params">(List desc,List src)</span>:复制</span><br></pre></td></tr></table></figure>

<p>Arrays常用的方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> List <span class="title function_">asList</span><span class="params">(T...t)</span>:创建一个List，将添加多个元素</span><br><span class="line"><span class="keyword">static</span> T <span class="title function_">binarySearch</span><span class="params">()</span>:二分查找</span><br><span class="line"><span class="keyword">static</span> T[] copyRange(<span class="type">int</span>[],start,end);</span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">sort</span><span class="params">()</span>;</span><br><span class="line"><span class="keyword">static</span> String <span class="title function_">toString</span><span class="params">()</span>;</span><br></pre></td></tr></table></figure>

<h2 id="Comparable"><a href="#Comparable" class="headerlink" title="Comparable"></a><strong>Comparable</strong></h2><blockquote>
<p>Comparable是自然排序的接口，实现此接口的类，就拥有了比较大小的能力</p>
<p>此接口中的方法只有一个</p>
<p>public int comparareTo(T t){</p>
<p>}</p>
<p>返回值说明   </p>
<p>正数：当前对象与比t大</p>
<p>0：当前对象与t相等</p>
<p>负数：当前对象比t小</p>
</blockquote>
<h2 id="Comparator"><a href="#Comparator" class="headerlink" title="Comparator"></a><strong>Comparator</strong></h2><blockquote>
<p>自定义的比较器   </p>
<p>Comparator接口中包含一个方法</p>
</blockquote>
<blockquote>
<p>Comparator与Comparable的区别</p>
<p>1.Comparable为可排序的，也被称为自然排序或内部比较器，实现该接口的类的对象自动拥有可排序功能。</p>
<p>2.Comparator为比较器，也被称为外部比较器，实现该接口可以定义一个针对某个类的排序方式。</p>
<p>3.Comparator与Comparable同时存在的情况下，前者优先级高</p>
</blockquote>
<h2 id="ArrayList源码分析"><a href="#ArrayList源码分析" class="headerlink" title="ArrayList源码分析"></a><strong>ArrayList</strong>源码分析</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">transient</span> Object[]elementData; <span class="comment">//定义一个Object数组，用来存储数组的元素，此数组可以扩</span></span><br><span class="line">容   </span><br><span class="line"><span class="comment">//2.构造方法</span></span><br><span class="line"><span class="keyword">public</span> <span class="title function_">ArrayList</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="built_in">this</span>.elementData=DEFAULTCAPACITY_EMPTY_ELEMENTDATA;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//给一个初使长度</span></span><br><span class="line"><span class="keyword">public</span> <span class="title function_">ArrayList</span><span class="params">(<span class="type">int</span> initialCapacity)</span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(initialCapacity&gt;<span class="number">0</span>)&#123;</span><br><span class="line">        <span class="built_in">this</span>.elementData=<span class="keyword">new</span> <span class="title class_">Object</span>[initialCapacity];</span><br><span class="line">    &#125;<span class="keyword">else</span> <span class="keyword">if</span>(initialCapacity==<span class="number">0</span>)&#123;</span><br><span class="line">        <span class="built_in">this</span>.elementData=EMPTY_ELEMENTDATA;</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">IllegalArgumentException</span>(<span class="string">&quot;Illegal Capacity: &quot;</span>+</span><br><span class="line">                initialCapacity);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//3.add方法</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">add</span><span class="params">(E e)</span>&#123;modCount++;</span><br><span class="line">    add(e,elementData,size);</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">add</span><span class="params">(E e,Object[]elementData,<span class="type">int</span> s)</span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(s==elementData.length)</span><br><span class="line">        elementData=grow();</span><br><span class="line">    elementData[s]=e;</span><br><span class="line">    size=s+<span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="数组总结"><a href="#数组总结" class="headerlink" title="数组总结"></a>数组总结</h3><blockquote>
<p>数组的特点：元素之间的地址是连续的   </p>
<p>get(index):时间复杂度是O(1)</p>
<p>set(index,E):O(1)</p>
<p>add(index,E):时间复杂度是O(n)</p>
<p>remove(index):O(n)</p>
</blockquote>
<h2 id="链表"><a href="#链表" class="headerlink" title="链表"></a>链表</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//内部结节</span></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">Node</span>&lt;E&gt; &#123;</span><br><span class="line">    E item;</span><br><span class="line">    Node&lt;E&gt; next;</span><br><span class="line">    Node&lt;E&gt; prev;</span><br><span class="line">    Node(Node&lt;E&gt; prev, E element, Node&lt;E&gt; next) &#123;</span><br><span class="line">        <span class="built_in">this</span>.item = element;</span><br><span class="line">        <span class="built_in">this</span>.next = next;</span><br><span class="line">        <span class="built_in">this</span>.prev = prev;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Stack"><a href="#Stack" class="headerlink" title="Stack"></a><strong>Stack</strong></h2><blockquote>
<p>Stack是栈  特点是先进后出 </p>
<p>​       LIFO：last in first out</p>
<p>方法:</p>
<p>​      push:压栈  </p>
<p>​      pop:弹出</p>
<p>​       peek:获得栈顶的元素</p>
<p>栈的用途：</p>
<p>悔棋</p>
<p>撤销</p>
<p>方法的调用</p>
</blockquote>
<h2 id="Queue"><a href="#Queue" class="headerlink" title="Queue"></a><strong>Queue</strong></h2><blockquote>
<p>Queue是一个队列，它的特点是先进先出（FIFO）</p>
</blockquote>
<h2 id="双端队列"><a href="#双端队列" class="headerlink" title="双端队列"></a>双端队列</h2><blockquote>
<p>Deque &#x3D;dubole ended queue</p>
<p>两端都可以插入和删除元素   </p>
<p>方法如下   </p>
<p>​    addFirst</p>
<p>​    addLast</p>
<p>​    removeFist</p>
<p>​    removeLast</p>
<p>​    offerFirst</p>
<p>​    offerLast</p>
<p>​    pollFirst</p>
<p>​    pollLast</p>
</blockquote>
<h1 id="集合框架2"><a href="#集合框架2" class="headerlink" title="集合框架2"></a>集合框架2</h1><h2 id="Set"><a href="#Set" class="headerlink" title="Set"></a>Set</h2><blockquote>
<p>Set:是Collection的子接口，无序，不可重复</p>
<p>三个主要的实现类   </p>
<p>HashSet:hash</p>
<p>LinkedHashList:有顺序   </p>
<p>TreeSet:排序的，内部是树   </p>
</blockquote>
<h2 id="Iterator"><a href="#Iterator" class="headerlink" title="Iterator"></a><strong>Iterator</strong></h2><blockquote>
<p>迭代器   用来从所有的Collection集合中遍历数组   提供三个方法   </p>
<p>boolean hasNext():是否有下一个未遍历到的元素   </p>
<p>E next():取出一个元素   </p>
<p>void remove():删除正在取出的元素   </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//代码模版如下   </span></span><br><span class="line">Iteartor ite=collection.iterator();</span><br><span class="line">    <span class="keyword">while</span>(ite.hasNext())&#123;</span><br><span class="line">    E e=ite.next();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="LinkedHashSet"><a href="#LinkedHashSet" class="headerlink" title="LinkedHashSet"></a><strong>LinkedHashSet</strong></h2><blockquote>
<p>LinkedHashSet是对HashSet的扩展，内部也是一个HashSet,但是按存入的顺序进行排列的</p>
<p>LinkdeHashSet中的元素也是不可重复的</p>
</blockquote>
<h2 id="SortedSet"><a href="#SortedSet" class="headerlink" title="SortedSet"></a><strong>SortedSet</strong></h2><blockquote>
<p>SortedSet:是Set的子接口，具备排序的能力   </p>
<p>TreeSet：是SortedSet的实现类，内部是一个树结构</p>
</blockquote>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/25/0f0daa7cf5dd4d9f.png"></p>
<h2 id="Map"><a href="#Map" class="headerlink" title="Map"></a><strong>Map</strong></h2><blockquote>
<p>1.Map是集合框架中的另一个顶层接口  Map结构的特点是 kev-value</p>
<p>2.集合中，key 是不可以重复的</p>
<p>3.key 和 value的类型都是引用类型</p>
</blockquote>
<p>常用方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">put(k,v):增加一对元素</span><br><span class="line">putAll(Map):将map中的所有元素增加到集合中</span><br><span class="line">v <span class="title function_">get</span><span class="params">(k)</span>:根据key,来查找value</span><br><span class="line"><span class="title function_">remove</span><span class="params">(k)</span>:根据key,来删除元素（key-value）</span><br><span class="line"><span class="type">int</span> <span class="title function_">size</span><span class="params">()</span>:获取集合中元素的个数</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">isEmpty</span><span class="params">()</span>:是否为空</span><br><span class="line">clear():清空</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">containsKey</span><span class="params">(k)</span>:是否包含某个key</span><br><span class="line"><span class="type">boolean</span> <span class="title function_">containsValue</span><span class="params">(v)</span>:是否包含某个value</span><br><span class="line">#遍历</span><br><span class="line">Set <span class="title function_">keySet</span><span class="params">()</span>:得到所有的key的集合</span><br><span class="line">Collection <span class="title function_">values</span><span class="params">()</span>:获得所有value的集合</span><br><span class="line">entrySet():获得所有的元素的集合（Entry(key,value)）</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">    <span class="comment">//遍历的示例</span></span><br><span class="line">    Map&lt;Integer, String&gt; map = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;Integer, String&gt;();</span><br><span class="line"><span class="comment">//增加</span></span><br><span class="line">   map.put(<span class="number">1</span>,<span class="string">&quot;james&quot;</span>);</span><br><span class="line">   map.put(<span class="number">2</span>,<span class="string">&quot;jack&quot;</span>);</span><br><span class="line">   map.put(<span class="number">3</span>,<span class="string">&quot;james&quot;</span>);</span><br><span class="line">   map.put(<span class="number">4</span>,<span class="string">&quot;owen&quot;</span>);</span><br><span class="line">   map.put(<span class="number">3</span>,<span class="string">&quot;scott&quot;</span>);</span><br><span class="line">    <span class="comment">//1.如何遍历集合   keySet</span></span><br><span class="line">    Set&lt;Integer&gt; set = map.keySet();</span><br><span class="line">System.out.println(set);</span><br><span class="line"><span class="keyword">for</span>(</span><br><span class="line">    Integer k:set)</span><br><span class="line"></span><br><span class="line">    &#123;</span><br><span class="line">        System.out.println(k + <span class="string">&quot;:&quot;</span> + map.get(k));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//2.values</span></span><br><span class="line">    Collection&lt;String&gt; coll = map.values();</span><br><span class="line"><span class="keyword">for</span>(</span><br><span class="line">    String s:coll)</span><br><span class="line"></span><br><span class="line">    &#123;</span><br><span class="line">        System.out.println(s);</span><br><span class="line">    &#125;</span><br><span class="line">System.out.println(<span class="string">&quot;----------------&quot;</span>);</span><br><span class="line">    <span class="comment">//3.key-value</span></span><br><span class="line">    Set&lt;Entry&lt;Integer, String&gt;&gt; es = map.entrySet();</span><br><span class="line"><span class="keyword">for</span>(</span><br><span class="line">    Entry&lt;Integer, String&gt; e:es)</span><br><span class="line"></span><br><span class="line">    &#123;</span><br><span class="line">        System.out.println(e.getKey() + <span class="string">&quot;:&quot;</span> + e.getValue());</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h2 id="HashMap的内部结构"><a href="#HashMap的内部结构" class="headerlink" title="HashMap的内部结构"></a><strong>HashMap</strong>的内部结构</h2><blockquote>
<p>1.key-value在内部被封装成了一个内部类 Node</p>
<p>2.HashMap中定义了一个Node类型的数组用来保存元素</p>
<p>3.Node还是一个单向链表   当链表中的元素超过8时，则转换成红黑树</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">Node</span>&lt;K,V&gt; <span class="keyword">implements</span> <span class="title class_">Map</span>.Entry&lt;K,V&gt; &#123;</span><br><span class="line">    <span class="keyword">final</span> <span class="type">int</span> hash;</span><br><span class="line">    <span class="keyword">final</span> K key; <span class="comment">//key</span></span><br><span class="line">    V value; <span class="comment">//value</span></span><br><span class="line">    Node&lt;K,V&gt; next; <span class="comment">//下一个节点，Node是封装了key和value,同时也是一个单向链表   </span></span><br><span class="line">    Node(<span class="type">int</span> hash, K key, V value, Node&lt;K,V&gt; next) &#123;</span><br><span class="line">        <span class="built_in">this</span>.hash = hash;</span><br><span class="line">        <span class="built_in">this</span>.key = key;</span><br><span class="line">        <span class="built_in">this</span>.value = value;</span><br><span class="line">        <span class="built_in">this</span>.next = next;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">transient</span> Node&lt;K,V&gt;[] table; <span class="comment">//将所有的key-value对，即node，都存在table中，table是一个数组</span></span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//put方法</span></span><br><span class="line"><span class="keyword">public</span> V <span class="title function_">put</span><span class="params">(K key, V value)</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> putVal(hash(key), key, value, <span class="literal">false</span>, <span class="literal">true</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">    <span class="keyword">final</span> V <span class="title function_">putVal</span><span class="params">(<span class="type">int</span> hash, K key, V value, <span class="type">boolean</span> onlyIfAbsent,</span></span><br><span class="line"><span class="params">                   <span class="type">boolean</span> evict)</span> &#123;</span><br><span class="line">        Node&lt;K, V&gt;[] tab; <span class="comment">//table的引用</span></span><br><span class="line">        Node&lt;K, V&gt; p; <span class="comment">//元素中的首个Node节点   </span></span><br><span class="line">        <span class="type">int</span> n; <span class="comment">//table的长度</span></span><br><span class="line">        <span class="type">int</span> i; <span class="comment">//元素的下标   通过hash后，模运行（实际是 (n - 1) &amp; hash]）</span></span><br><span class="line">        <span class="keyword">if</span> ((tab = table) == <span class="literal">null</span> || (n = tab.length) == <span class="number">0</span>)</span><br><span class="line">            n = (tab = resize()).length; <span class="comment">//重新分配长度，算出tal的长度</span></span><br><span class="line"><span class="comment">//如果元素中无值，则将Node放在索引为i的下标下   </span></span><br><span class="line">        <span class="keyword">if</span> ((p = tab[i = (n - <span class="number">1</span>) &amp; hash]) == <span class="literal">null</span>)</span><br><span class="line">            tab[i] = newNode(hash, key, value, <span class="literal">null</span>);</span><br><span class="line">        <span class="keyword">else</span> &#123;</span><br><span class="line">            Node&lt;K, V&gt; e; <span class="comment">//如果有相同的key,e存储的是重复节点的引用   </span></span><br><span class="line">            K k;</span><br><span class="line"><span class="comment">//如果元素中的首Node与新节点相同   则</span></span><br><span class="line">            <span class="keyword">if</span> (p.hash == hash &amp;&amp;</span><br><span class="line">                    ((k = p.key) == key || (key != <span class="literal">null</span> &amp;&amp; key.equals(k))))</span><br><span class="line">                e = p;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span> (p <span class="keyword">instanceof</span> TreeNode) <span class="comment">//如果是树结点，则使用树节点的方式查找   </span></span><br><span class="line">                e = ((TreeNode&lt;K, V&gt;) p).putTreeVal(<span class="built_in">this</span>, tab, hash, key, value);</span><br><span class="line">            <span class="keyword">else</span> &#123;<span class="comment">//遍历链表，如果有重复的，将重复的节点赋值给e,并break,否则，将新节点加到</span></span><br><span class="line">                链表尾部</span><br><span class="line">                <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">binCount</span> <span class="operator">=</span> <span class="number">0</span>; ; ++binCount) &#123;</span><br><span class="line">                    <span class="keyword">if</span> ((e = p.next) == <span class="literal">null</span>) &#123;<span class="comment">//链表中最后一个结点</span></span><br><span class="line">                        p.next = newNode(hash, key, value, <span class="literal">null</span>);</span><br><span class="line"><span class="comment">//如果长度大于8，则转成树</span></span><br><span class="line">                        <span class="keyword">if</span> (binCount &gt;= TREEIFY_THRESHOLD - <span class="number">1</span>) <span class="comment">// -1 for 1st</span></span><br><span class="line">                            treeifyBin(tab, hash);</span><br><span class="line">                        <span class="keyword">break</span>;</span><br><span class="line">                    &#125;</span><br><span class="line"><span class="comment">//如果有重复的，则不再比较</span></span><br><span class="line">                    <span class="keyword">if</span> (e.hash == hash &amp;&amp;</span><br><span class="line">                            ((k = e.key) == key || (key != <span class="literal">null</span> &amp;&amp; key.equals(k))))</span><br><span class="line">                        <span class="keyword">break</span>;</span><br><span class="line">                    p = e;<span class="comment">//指向链表的下一个元素，用来遍历   </span></span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (e != <span class="literal">null</span>) &#123; <span class="comment">// existing mapping for key 如果有重复的，进行替换</span></span><br><span class="line">                <span class="type">V</span> <span class="variable">oldValue</span> <span class="operator">=</span> e.value;</span><br><span class="line">                <span class="keyword">if</span> (!onlyIfAbsent || oldValue == <span class="literal">null</span>)<span class="comment">//根据onlyIfAbsend决定是否替</span></span><br><span class="line">                    换</span><br><span class="line">                e.value = value;</span><br><span class="line">                afterNodeAccess(e);</span><br><span class="line">                <span class="keyword">return</span> oldValue;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        ++modCount;</span><br><span class="line">        <span class="keyword">if</span> (++size &gt; threshold)</span><br><span class="line">            resize();</span><br><span class="line">        afterNodeInsertion(evict);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h2 id="Hashtable"><a href="#Hashtable" class="headerlink" title="Hashtable"></a><strong>Hashtable</strong></h2><blockquote>
<p>Hashtable 是一个古老的 Map 实现类，不建议使用</p>
<p>Hashtable 是一个线程安全的 Map 实现，但 HashMap 是线程不安全的。</p>
<p>Hashtable 不允许使用 null 作为 key 和 value，而 HashMap 可以</p>
</blockquote>
<h2 id="TreeMap"><a href="#TreeMap" class="headerlink" title="TreeMap"></a><strong>TreeMap</strong></h2><blockquote>
<p>TreeMap 存储 Key-Value 对时，需要根据 Key 对 key-value 对进行排序。TreeMap 内部是同红黑</p>
<p>树来实现的。</p>
<p>TreeMap 的 Key 的排序：</p>
<p>自然排序：TreeMap 的所有的 Key 必须实现 Comparable 接口，而且所有的 Key 应该是同一个类的对</p>
<p>象，否则将会抛出 ClasssCastException</p>
<p>定制排序：创建 TreeMap 时，传入一个 Comparator 对象，该对象负责对 TreeMap 中的所有 key 进</p>
<p>行排序。此时不需要 Map 的 Key 实现 Comparable 接口</p>
</blockquote>
<h3 id=""><a href="#" class="headerlink" title=""></a></h3></article><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Java/">Java</a></div><div class="post_share"><div class="social-share" data-image="https://s3.bmp.ovh/imgs/2023/02/25/1a3e9c86350e5726.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/08/01/%E6%99%AE%E7%BD%97%E7%B1%B3%E4%BF%AE%E6%96%AF/" title="普罗米修斯"><img class="cover" src="https://picx.zhimg.com/v2-054f08672cf276642706e7968f4c7857_1440w.jpg?source=172ae18b" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">普罗米修斯</div></div></a></div><div class="next-post pull-right"><a href="/2023/02/24/Elasticsearch_%E5%85%A5%E9%97%A8/" title="Elasticsearch 入门"><img class="cover" src="https://s3.bmp.ovh/imgs/2023/02/24/bf33cc6c00297765.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Elasticsearch 入门</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#javaSE%E5%9F%BA%E7%A1%80"><span class="toc-number">1.</span> <span class="toc-text">javaSE基础</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#javaSe-%E6%95%B4%E4%BD%93%E5%A4%A7%E7%BA%B2"><span class="toc-number">1.1.</span> <span class="toc-text">javaSe 整体大纲</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%BA%E7%A1%80"><span class="toc-number">1.2.</span> <span class="toc-text">基础</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80%E7%9A%84%E5%8F%91%E5%B1%95%E5%8F%B2%EF%BC%88%E4%BA%86%E8%A7%A3%EF%BC%89"><span class="toc-number">1.3.</span> <span class="toc-text">编程语言的发展史（了解）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E6%98%AFjava"><span class="toc-number">1.4.</span> <span class="toc-text">为什么是java</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9E%E9%A1%BE"><span class="toc-number">1.5.</span> <span class="toc-text">回顾</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#java%E8%AF%AD%E8%A8%80%E7%9A%84%E5%8F%91%E5%B1%95"><span class="toc-number">1.6.</span> <span class="toc-text">java语言的发展</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#java-%E8%AF%AD%E8%A8%80%E7%9A%84%E7%89%B9%E7%82%B9"><span class="toc-number">1.7.</span> <span class="toc-text">java 语言的特点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#java%E8%AF%AD%E8%A8%80%E7%9A%84%E4%B8%89%E4%B8%AA%E7%89%88%E6%9C%AC"><span class="toc-number">1.8.</span> <span class="toc-text">java语言的三个版本</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85"><span class="toc-number">1.9.</span> <span class="toc-text">环境安装</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#JDK"><span class="toc-number">1.9.1.</span> <span class="toc-text">JDK</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85JDK"><span class="toc-number">1.10.</span> <span class="toc-text">安装JDK</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#DOS%E5%91%BD%E4%BB%A4"><span class="toc-number">1.11.</span> <span class="toc-text">DOS命令</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AC%AC%E4%B8%80%E4%B8%AAjava%E7%A8%8B%E5%BA%8F"><span class="toc-number">1.12.</span> <span class="toc-text">第一个java程序</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HelloWorld%E8%AF%A6%E8%A7%A3"><span class="toc-number">1.13.</span> <span class="toc-text">HelloWorld详解</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#java%E5%91%BD%E4%BB%A4"><span class="toc-number">1.14.</span> <span class="toc-text">java命令</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B3%A8%E9%87%8A"><span class="toc-number">1.15.</span> <span class="toc-text">注释</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#java%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80"><span class="toc-number">2.</span> <span class="toc-text">java编程基础</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">2.1.</span> <span class="toc-text">关键字</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A0%87%E8%AF%86%E7%AC%A6"><span class="toc-number">2.2.</span> <span class="toc-text">标识符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%98%E9%87%8F"><span class="toc-number">2.3.</span> <span class="toc-text">变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.4.</span> <span class="toc-text">数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.4.1.</span> <span class="toc-text">基本数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B4%E6%95%B0%EF%BC%9A"><span class="toc-number">2.4.1.1.</span> <span class="toc-text">整数：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%B3%E4%BA%8E%E5%AE%B9%E9%87%8F%E7%9A%84%E6%8D%A2%E7%AE%97%E5%85%B3%E7%B3%BB"><span class="toc-number">2.4.1.2.</span> <span class="toc-text">关于容量的换算关系</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BF%9B%E5%88%B6%E7%9A%84%E8%BD%AC%E6%8D%A2"><span class="toc-number">2.4.1.3.</span> <span class="toc-text">进制的转换</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E9%9D%A2%E5%80%BC%EF%BC%88literal%EF%BC%89"><span class="toc-number">2.4.2.</span> <span class="toc-text">字面值（literal）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%AE%E7%82%B9%E5%9E%8B"><span class="toc-number">2.4.3.</span> <span class="toc-text">浮点型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E5%9E%8B"><span class="toc-number">2.4.4.</span> <span class="toc-text">字符型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#boolean"><span class="toc-number">2.4.5.</span> <span class="toc-text">boolean</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#String%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.4.6.</span> <span class="toc-text">String类型</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#java%E4%BB%A3%E7%A0%81%E4%B8%89%E7%BA%A7%E8%B7%B3"><span class="toc-number">2.5.</span> <span class="toc-text">java代码三级跳</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E7%9A%84%E8%BD%AC%E6%8D%A2"><span class="toc-number">2.6.</span> <span class="toc-text">数据类型的转换</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%87%AA%E5%8A%A8%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2%E5%8F%91%E7%94%9F%E5%9C%A8%E4%B8%A4%E7%A7%8D%E6%83%85%E5%86%B5"><span class="toc-number">2.6.0.1.</span> <span class="toc-text">自动类型转换发生在两种情况</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BC%BA%E5%88%B6%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-number">2.6.0.2.</span> <span class="toc-text">强制类型转换</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Scanner"><span class="toc-number">2.7.</span> <span class="toc-text">Scanner</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.8.</span> <span class="toc-text">运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.8.1.</span> <span class="toc-text">算术运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B5%8B%E5%80%BC%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.8.2.</span> <span class="toc-text">赋值运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.8.3.</span> <span class="toc-text">比较运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.8.4.</span> <span class="toc-text">逻辑运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%8D%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.8.5.</span> <span class="toc-text">位运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9D%A1%E4%BB%B6%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.8.6.</span> <span class="toc-text">条件运算符</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Java%E8%BF%9B%E9%98%B6"><span class="toc-number">3.</span> <span class="toc-text">Java进阶</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6"><span class="toc-number">3.1.</span> <span class="toc-text">流程控制</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%86%E6%94%AF%E8%AF%AD%E5%8F%A5"><span class="toc-number">3.2.</span> <span class="toc-text">分支语句</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#if%E8%AF%AD%E5%8F%A5"><span class="toc-number">3.3.</span> <span class="toc-text">if语句</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8D%95%E5%88%86%E6%94%AF"><span class="toc-number">3.3.1.</span> <span class="toc-text">单分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%8C%E5%88%86%E6%94%AF"><span class="toc-number">3.3.2.</span> <span class="toc-text">双分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%9A%E5%88%86%E6%94%AF"><span class="toc-number">3.3.3.</span> <span class="toc-text">多分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#if%E7%9A%84%E5%B5%8C%E5%A5%97"><span class="toc-number">3.3.4.</span> <span class="toc-text">if的嵌套</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#if%E8%AF%AD%E5%8F%A5%E7%9A%84%E7%AE%80%E5%8C%96"><span class="toc-number">3.3.5.</span> <span class="toc-text">if语句的简化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#switch-%E8%AF%AD%E5%8F%A5"><span class="toc-number">3.3.6.</span> <span class="toc-text">switch 语句</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BE%AA%E7%8E%AF"><span class="toc-number">3.4.</span> <span class="toc-text">循环</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BE%AA%E7%8E%AF%E8%AF%AD%E5%8F%A5%E7%9A%84%E4%B8%89%E4%B8%AA%E9%83%A8%E5%88%86"><span class="toc-number">3.4.1.</span> <span class="toc-text">循环语句的三个部分</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#java%E4%B8%AD%EF%BC%8C%E5%BE%AA%E7%8E%AF%E8%AF%AD%E5%8F%A5%E7%9A%84%E5%88%86%E7%B1%BB"><span class="toc-number">3.4.2.</span> <span class="toc-text">java中，循环语句的分类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#while%E8%AF%AD%E5%8F%A5"><span class="toc-number">3.4.3.</span> <span class="toc-text">while语句</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%AD%BB%E5%BE%AA%E7%8E%AF"><span class="toc-number">3.4.4.</span> <span class="toc-text">死循环</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E7%9A%84%E4%BD%9C%E7%94%A8%E5%9F%9F"><span class="toc-number">3.4.5.</span> <span class="toc-text">变量的作用域</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#do-while"><span class="toc-number">3.4.6.</span> <span class="toc-text">do-while</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#for%E5%BE%AA%E7%8E%AF"><span class="toc-number">3.4.7.</span> <span class="toc-text">for循环</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#break-%E4%B8%8E-continue"><span class="toc-number">3.4.8.</span> <span class="toc-text">break 与 continue</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B5%8C%E5%A5%97%E5%BE%AA%E7%8E%AF"><span class="toc-number">3.4.9.</span> <span class="toc-text">嵌套循环</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BE%AA%E7%8E%AF%E4%B8%AD%E7%9A%84%E7%AE%97%E6%B3%95"><span class="toc-number">3.4.10.</span> <span class="toc-text">循环中的算法</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E7%BB%84"><span class="toc-number">3.5.</span> <span class="toc-text">数组</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E7%9A%84%E5%AE%9A%E4%B9%89"><span class="toc-number">3.5.1.</span> <span class="toc-text">数组的定义</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E7%BB%84-1"><span class="toc-number">3.5.2.</span> <span class="toc-text">数组</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%85%E5%AD%98%E6%A8%A1%E5%9E%8B"><span class="toc-number">3.5.3.</span> <span class="toc-text">内存模型</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%92%E5%BA%8F%E5%8F%8A%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84"><span class="toc-number">3.6.</span> <span class="toc-text">排序及二维数组</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AE%97%E6%B3%95"><span class="toc-number">3.6.1.</span> <span class="toc-text">算法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8E%92%E5%BA%8F"><span class="toc-number">3.6.2.</span> <span class="toc-text">排序</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E5%88%86%E6%B3%95"><span class="toc-number">3.6.3.</span> <span class="toc-text">二分法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E4%BD%8D%E6%95%B0%E7%BB%84"><span class="toc-number">3.6.4.</span> <span class="toc-text">二位数组</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1OOP"><span class="toc-number">4.</span> <span class="toc-text">面向对象OOP</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9D%A2%E5%90%91%E8%BF%87%E7%A8%8B%E4%B8%8E%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1"><span class="toc-number">4.1.</span> <span class="toc-text">面向过程与面向对象</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86"><span class="toc-number">4.2.</span> <span class="toc-text">面向对象的基础知识</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E5%AF%B9%E8%B1%A1"><span class="toc-number">4.2.1.</span> <span class="toc-text">什么是对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%B1%BB"><span class="toc-number">4.2.2.</span> <span class="toc-text">类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9A%E4%B9%89%E7%B1%BB%E7%9A%84%E8%AF%AD%E6%B3%95"><span class="toc-number">4.2.3.</span> <span class="toc-text">定义类的语法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%B9%E6%B3%95"><span class="toc-number">4.2.4.</span> <span class="toc-text">方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%85%E5%AD%98%E7%BB%93%E6%9E%84"><span class="toc-number">4.2.5.</span> <span class="toc-text">内存结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%B9%E6%B3%95%E7%9A%84%E4%BC%A0%E5%8F%82"><span class="toc-number">4.2.6.</span> <span class="toc-text">方法的传参</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%87%8D%E8%BD%BD%EF%BC%88overload%EF%BC%89"><span class="toc-number">4.2.7.</span> <span class="toc-text">重载（overload）</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E5%8F%8A%E7%BB%A7%E6%89%BF"><span class="toc-number">4.3.</span> <span class="toc-text">构造方法及继承</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95"><span class="toc-number">4.3.1.</span> <span class="toc-text">构造方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%BB%98%E8%AE%A4%E7%9A%84%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95"><span class="toc-number">4.3.2.</span> <span class="toc-text">默认的构造方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E4%B8%8D%E8%BF%94%E5%9B%9E%E5%80%BC"><span class="toc-number">4.3.3.</span> <span class="toc-text">构造方法不返回值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%B1%E8%BF%91%E5%8E%9F%E5%88%99"><span class="toc-number">4.3.4.</span> <span class="toc-text">就近原则</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#this%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">4.3.5.</span> <span class="toc-text">this关键字</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8C%BF%E5%90%8D%E5%9D%97"><span class="toc-number">4.3.6.</span> <span class="toc-text">匿名块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B3%E4%BA%8E%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E7%9A%84%E5%B0%8F%E7%BB%93"><span class="toc-number">4.3.7.</span> <span class="toc-text">关于构造方法的小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8C%85%E7%AE%A1%E7%90%86"><span class="toc-number">4.4.</span> <span class="toc-text">包管理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%A7%E6%89%BF"><span class="toc-number">4.5.</span> <span class="toc-text">继承</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%B9%E6%B3%95%E9%87%8D%E5%86%99"><span class="toc-number">4.5.1.</span> <span class="toc-text">方法重写</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B3%E4%BA%8E%E7%BB%A7%E6%89%BF%E7%9A%84%E5%B0%8F%E7%BB%93"><span class="toc-number">4.5.2.</span> <span class="toc-text">关于继承的小结</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#super%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">4.5.3.</span> <span class="toc-text">super关键字</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%9A%E6%80%81%E5%92%8C%E5%B0%81%E8%A3%85"><span class="toc-number">4.6.</span> <span class="toc-text">多态和封装</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%9A%E6%80%81"><span class="toc-number">4.6.1.</span> <span class="toc-text">多态</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BC%96%E8%AF%91%E6%97%B6%E7%B1%BB%E5%9E%8B"><span class="toc-number">4.6.2.</span> <span class="toc-text">编译时类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%90%E8%A1%8C%E6%97%B6%E7%B1%BB%E5%9E%8B"><span class="toc-number">4.6.3.</span> <span class="toc-text">运行时类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-number">4.6.4.</span> <span class="toc-text">类型转换</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%81%E8%A3%85"><span class="toc-number">4.6.5.</span> <span class="toc-text">封装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%BF%E9%97%AE%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-number">4.6.6.</span> <span class="toc-text">访问修饰符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-number">4.6.7.</span> <span class="toc-text">修饰符</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#final"><span class="toc-number">4.6.7.1.</span> <span class="toc-text">final</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#static"><span class="toc-number">4.6.7.2.</span> <span class="toc-text">static</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E5%9D%97"><span class="toc-number">4.6.7.3.</span> <span class="toc-text">静态块</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F"><span class="toc-number">4.6.7.4.</span> <span class="toc-text">单例模式</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8A%BD%E8%B1%A1%E7%B1%BB%E4%B8%8E%E6%8E%A5%E5%8F%A3"><span class="toc-number">5.</span> <span class="toc-text">抽象类与接口</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#abstract"><span class="toc-number">5.1.</span> <span class="toc-text">abstract</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3"><span class="toc-number">5.2.</span> <span class="toc-text">接口</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3%E4%B8%8E%E7%B1%BB"><span class="toc-number">5.2.1.</span> <span class="toc-text">接口与类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3%E4%B8%8E%E6%8A%BD%E8%B1%A1%E7%B1%BB%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">5.2.2.</span> <span class="toc-text">接口与抽象类的区别</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%B1%BB%E5%92%8C%E7%B1%BB%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB"><span class="toc-number">5.2.3.</span> <span class="toc-text">类和类之间的关系</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BB%A7%E6%89%BF-1"><span class="toc-number">5.2.3.1.</span> <span class="toc-text">继承</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0"><span class="toc-number">5.2.3.2.</span> <span class="toc-text">实现</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BE%9D%E8%B5%96"><span class="toc-number">5.2.3.3.</span> <span class="toc-text">依赖</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%B3%E8%81%94"><span class="toc-number">5.2.3.4.</span> <span class="toc-text">关联</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%81%9A%E5%90%88"><span class="toc-number">5.2.3.5.</span> <span class="toc-text">聚合</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BB%84%E5%90%88"><span class="toc-number">5.2.3.6.</span> <span class="toc-text">组合</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%AE%BE%E8%AE%A1%E6%80%9D%E6%83%B3"><span class="toc-number">5.2.3.7.</span> <span class="toc-text">设计思想</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">5.2.4.</span> <span class="toc-text">内部类</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">5.2.4.1.</span> <span class="toc-text">静态内部类</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%88%90%E5%91%98%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">5.2.4.2.</span> <span class="toc-text">成员内部类</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E6%B3%95%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">5.2.4.3.</span> <span class="toc-text">方法内部类</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8C%BF%E5%90%8D%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">5.2.4.4.</span> <span class="toc-text">匿名内部类</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E7%B1%BB"><span class="toc-number">6.</span> <span class="toc-text">常用类</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#lang%E5%8C%85"><span class="toc-number">6.1.</span> <span class="toc-text">lang包</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#System%E7%B1%BB"><span class="toc-number">6.2.</span> <span class="toc-text">System类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8C%85%E8%A3%85%E7%B1%BB"><span class="toc-number">6.3.</span> <span class="toc-text">包装类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Math"><span class="toc-number">6.4.</span> <span class="toc-text">Math</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#object%E7%B1%BB"><span class="toc-number">6.5.</span> <span class="toc-text">object类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#hashcode%E6%96%B9%E6%B3%95"><span class="toc-number">6.5.1.</span> <span class="toc-text">hashcode方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#equals%E6%96%B9%E6%B3%95"><span class="toc-number">6.5.2.</span> <span class="toc-text">equals方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#toString%E6%96%B9%E6%B3%95"><span class="toc-number">6.5.3.</span> <span class="toc-text">toString方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#getClass-%E6%96%B9%E6%B3%95"><span class="toc-number">6.5.4.</span> <span class="toc-text">**getClass()**方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#String-%E7%B1%BB"><span class="toc-number">6.5.5.</span> <span class="toc-text">String 类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%B1%BB"><span class="toc-number">6.5.6.</span> <span class="toc-text">字符串类</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%AF%94%E8%BE%83%E6%96%B9%E6%B3%95"><span class="toc-number">6.5.6.1.</span> <span class="toc-text">字符串比较方法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%B1%A0"><span class="toc-number">6.5.6.2.</span> <span class="toc-text">字符串池</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2"><span class="toc-number">6.5.6.3.</span> <span class="toc-text">字符串转换</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#StringBuffer"><span class="toc-number">6.5.6.4.</span> <span class="toc-text">StringBuffer</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#StringBuilder"><span class="toc-number">6.5.6.5.</span> <span class="toc-text">StringBuilder</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BC%82%E5%B8%B8"><span class="toc-number">7.</span> <span class="toc-text">异常</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%82%E5%B8%B8%E6%A6%82%E5%BF%B5"><span class="toc-number">7.1.</span> <span class="toc-text">异常概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%82%E5%B8%B8%E7%9A%84%E4%BD%93%E7%B3%BB%E7%BB%93%E6%9E%84"><span class="toc-number">7.2.</span> <span class="toc-text">异常的体系结构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86"><span class="toc-number">7.3.</span> <span class="toc-text">异常处理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%82%E5%B8%B8%E5%88%86%E7%B1%BB"><span class="toc-number">7.4.</span> <span class="toc-text">异常分类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#throws"><span class="toc-number">7.5.</span> <span class="toc-text">throws</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#throw%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">7.6.</span> <span class="toc-text">throw关键字</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#throw%E5%92%8Cthrows%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">7.7.</span> <span class="toc-text">throw和throws的区别</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="toc-number">8.</span> <span class="toc-text">工具类</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#random%E7%B1%BB"><span class="toc-number">8.1.</span> <span class="toc-text">random类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Date-%E7%B1%BB"><span class="toc-number">8.2.</span> <span class="toc-text">Date 类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Calendar"><span class="toc-number">8.3.</span> <span class="toc-text">Calendar</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SimpleDateFormat"><span class="toc-number">8.4.</span> <span class="toc-text">SimpleDateFormat</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%9B%86%E5%90%88%E6%A1%86%E6%9E%B6"><span class="toc-number">9.</span> <span class="toc-text">集合框架</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9B%86%E5%90%88%E6%A1%86%E6%9E%B6-1"><span class="toc-number">9.1.</span> <span class="toc-text">集合框架</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Collection%E6%8E%A5%E5%8F%A3"><span class="toc-number">9.2.</span> <span class="toc-text">Collection接口</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B3%9B%E5%9E%8B"><span class="toc-number">9.3.</span> <span class="toc-text">泛型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%97%E6%B3%95%E7%B1%BB"><span class="toc-number">9.4.</span> <span class="toc-text">算法类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Comparable"><span class="toc-number">9.5.</span> <span class="toc-text">Comparable</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Comparator"><span class="toc-number">9.6.</span> <span class="toc-text">Comparator</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ArrayList%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90"><span class="toc-number">9.7.</span> <span class="toc-text">ArrayList源码分析</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E6%80%BB%E7%BB%93"><span class="toc-number">9.7.1.</span> <span class="toc-text">数组总结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%93%BE%E8%A1%A8"><span class="toc-number">9.8.</span> <span class="toc-text">链表</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Stack"><span class="toc-number">9.9.</span> <span class="toc-text">Stack</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Queue"><span class="toc-number">9.10.</span> <span class="toc-text">Queue</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%8C%E7%AB%AF%E9%98%9F%E5%88%97"><span class="toc-number">9.11.</span> <span class="toc-text">双端队列</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%9B%86%E5%90%88%E6%A1%86%E6%9E%B62"><span class="toc-number">10.</span> <span class="toc-text">集合框架2</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Set"><span class="toc-number">10.1.</span> <span class="toc-text">Set</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Iterator"><span class="toc-number">10.2.</span> <span class="toc-text">Iterator</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#LinkedHashSet"><span class="toc-number">10.3.</span> <span class="toc-text">LinkedHashSet</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#SortedSet"><span class="toc-number">10.4.</span> <span class="toc-text">SortedSet</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Map"><span class="toc-number">10.5.</span> <span class="toc-text">Map</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HashMap%E7%9A%84%E5%86%85%E9%83%A8%E7%BB%93%E6%9E%84"><span class="toc-number">10.6.</span> <span class="toc-text">HashMap的内部结构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Hashtable"><span class="toc-number">10.7.</span> <span class="toc-text">Hashtable</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#TreeMap"><span class="toc-number">10.8.</span> <span class="toc-text">TreeMap</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">10.8.1.</span> <span class="toc-text"></span></a></li></ol></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By Reisen</div><div class="footer_custom_text">I wish you to become your own sun, no need to rely on who's light</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><canvas id="universe"></canvas><script defer src="/js/universe.js"></script><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-show-text.min.js" data-mobile="false" data-text="I,LOVE,YOU" data-fontsize="15px" data-random="false" async="async"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"]):not([href="/music/"]):not([href="/no-pjax/"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div><!-- hexo injector body_end start --><script data-pjax>
  function butterfly_clock_anzhiyu_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock_anzhiyu')
    if(parent_div_git) {
      parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = '/';
  var qweather_key = 'b16a1fa0e63c46a4b8f28abfb06ae3fe';
  var gaud_map_key = 'e2b04289e870b005374ee030148d64fd&s=rsv3';
  var baidu_ak_key = 'undefined';
  var flag = 0;
  var clock_rectangle = '113.34532,23.15624';
  var clock_default_rectangle_enable = 'false';

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_anzhiyu_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_anzhiyu_injector_config();
  }
  </script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script data-pjax src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.js"></script><!-- hexo injector body_end end --></body></html>